UITextView setText should not jump to top in ios8 - scroll

Following iOS 8 code is called every second:
- (void)appendString(NSString *)newString toTextView:(UITextView *)textView {
textView.scrollEnabled = NO;
textView.text = [NSString stringWithFormat:#"%#%#%#", textView.text, newString, #"\n"];
textView.scrollEnabled = YES;
[textView scrollRangeToVisible:NSMakeRange(textView.text.length, 0)];
}
The goal is to have the same scrolling down behaviour as the XCode console when the text starts running off the bottom. Unfortunately, setText causes the view to reset to the top before I can scroll down again with scrollRangeToVisible.
This was solved in iOS7 with the above code and it worked, but after upgrading last week to iOS8, that solution no longer seems to work anymore.
I can't figure out how to get this going fluently without the jumping behaviour?

I meet this problem too. You can try this.
textView.layoutManager.allowsNonContiguousLayout = NO;
refrence:http://hayatomo.com/2014/09/26/1307

The following two solutions don't work for me on iOS 8.0.
textView.scrollEnabled = NO;
[textView.setText: text];
textView.scrollEnabled = YES;
and
CGPoint offset = textView.contentOffset;
[textView.setText: text];
[textView setContentOffset:offset];
I setup a delegate to the textview to monitor the scroll event, and noticed that after my operation to restore the offset, the offset is reset to 0 again. So I instead use the main operation queue to make sure my restore operation happens after the "reset to 0" option.
Here's my solution that works for iOS 8.0.
CGPoint offset = self.textView.contentOffset;
self.textView.attributedText = replace;
[[NSOperationQueue mainQueue] addOperationWithBlock: ^{
[self.textView setContentOffset: offset];
}];

Try just to add text to UITextView (without scrollRangeToVisible/scrollEnabled). It seams that hack with scroll enabled/disabled is no more needed in iOS8 SDK. UITextView scrolls automatically.

Related

tvOS 14.3 UISearchController: How to locked in display

Short version, is there a way to make this 14.3 look
into this prior to 14.3
Long version,
In every OS iteration the look of the UISearchController is changing. Before it only change the keyboard portion but with 14.3 it changed that the keyboard portion is on left side while the search results are on the right, which is what we don't like since we have custom view and overlays on top of it.
Any APIs to make it revert to the previous iteration, that is the keyboard are all within one horizontal line and search results on bottom, and stay that way forever?
Here's the code for the integration. The 14.3 UI look did mess up the app overall.
_searchResults = [[UITableViewController alloc] init];
_searchController = [[UISearchController alloc] initWithSearchResultsController:_searchResults];
_searchController.searchResultsUpdater = self;
_searchController.view.backgroundColor = [UIColor clearColor];
_searchController.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
_searchController.searchBar.placeholder = #"TV Shows, Movies, Keywords";
_searchController.obscuresBackgroundDuringPresentation = false;
_searchController.hidesNavigationBarDuringPresentation = true;
_searchContainer = [[UISearchContainerViewController alloc] initWithSearchController:_searchController];
_navController = [[UINavigationController alloc] initWithRootViewController:_searchContainer];
[_navController willMoveToParentViewController:self];
[self addChildViewController:_navController];
[self.view addSubview:_navController.view];
There is no code to change keyboard looking but it's simply changed on your device setting:
Settings>General>Keyboard = Auto
but you can changed to "Linear" or "Grid"
for more information see the video:
Discover search suggestions for Apple TV

xcode ios NSRangeException on creating subviews

how do I change the code below to fix the pickerView being depreciated?
This code has worked well before and did the job. I havent needed to compile for a while and when I was fixing another problem I bumped into this NSRangeException when it hits the subview. The code used to work with a previous version of IOS. Any thoughts would be appreciated.
Terminating app due to uncaught exception 'NSRangeException', reason:
'-[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
First throw call stack:... etc etc
After more reading I find that the pickerView is depreciated.
Never will understand why Apple can just change code!
-(void)willPresentActionSheet:(UIActionSheet *)actionSheet {
switch ([actionSheet tag] ) {
case 1://date
{
NSDate *d;
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 50, 100, 116)];
[pickerView setTag:100+[actionSheet tag]];
[pickerView setDatePickerMode:UIDatePickerModeDate];
if( DefDate == #"" || DefDate == Nil ) DefDate = [fun0 GetCurrentDate];
d = [fun0 GetDatefromString:DefDate];
[pickerView setDate:d animated:YES];
[actionSheet addSubview:pickerView];
[pickerView release];
NSArray *subViews = [actionSheet subviews];
**// Line below is where is where it dumps:**
[[subViews objectAtIndex: SelectButtonIndex] setFrame:CGRectMake(20, 266, 280, 46)];
[[subViews objectAtIndex:CancelButtonIndex] setFrame:CGRectMake(20, 317, 280, 46)];
}
break;
}
}
- (IBAction)btnDate:(id)sender {
UIActionSheet *asheet = [[UIActionSheet alloc]
initWithTitle:#"Pick the date of your meal"
delegate:self
cancelButtonTitle:#""
destructiveButtonTitle:nil
otherButtonTitles:#"Select"
, nil];
[asheet setTag:1];
[asheet showInView:[self.view superview]];
[asheet setFrame:CGRectMake(0, 117, 320, 383)];
[asheet release];
}
I've tested it with iOS 8.0 (and running on XCode6.1) and above, and your code and UIActionSheet both looks nice.
It can compile, run and showing me the output.
Here's what I get.
Update:
From iOS 8.0 and above, UIActionSheet is depreciated. Also its stop supporting add subviews too. This means device with iOS 8.0 and above will not show you UIDatePicker as subview of it. If notice, nightmare is not the error line you've specified below the comment but its not showing data picker any more inside action sheet.
From Documentation,
UIActionSheet is not designed to be subclassed, nor should you add
views to its hierarchy. If you need to present a sheet with more
customization than provided by the UIActionSheet API, you can create
your own and present it modally with
presentViewController:animated:completion:.
IMHO,
You should upgrade your app and code to start supporting from iOS 8.0 only. UIActionSheet will be replace by UIAlertController. [Suggested]
If you wish to support back iOS 8 then you've to use a third party action sheet which you can use in place of UIActionSheet in all iOS versions. Here's the one, https://github.com/skywinder/ActionSheetPicker-3.0 [Good Alternative]
If you don't want to use third party and still wants to support all iOS versions, then you can runtime check for iOS versions and based on that you can either show UIActionSheet and UIAlertController. [Not Recommended]
Few links which may help you.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/
http://nshipster.com/uialertcontroller/
Add UIPickerView in UIActionSheet from IOS 8 not working
Showing a UIPickerView with UIActionSheet in iOS8 not working
Action Sheet Picker worked great as I was able to chat directly with the developer to get going. I guess It took me a little while to get going understanding it as I dont program in IOS every day, but once I did its awesome! Thank you to Hemang above for all the suggestions!
ACTION SHEET PICKER

UISplitView crashing after selecting a row

I have a UISPlitViewController, I have a UITableView in my rootView and have a detailView, on select of second row in my rootView, what i am trying to do is: remove the UISplitViewController and add a new UISplitViewController (based on my requirement), so in the portrait mode when i select second row from the popOver, the application crashing? (but works well in landscape mode).
I'm 100% sure I can answer the question, but it would help if you posted some code. What code are you using now that is working for landscape but crashes in portrait?
(I would've written this in a comment, but I need 50 rep for that).
[splitViewController.view removeFromSuperview];
splitViewController = [[UISplitViewController alloc] init];
rootObj = [[HotelsRootViewController alloc] init];
mapObj = [[mapViewController alloc] init];
rootObj.mapObj = mapObj;
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootObj];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:mapObj];
[mapObj release];
splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
splitViewController.delegate=mapObj;
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
This is what i do on selection of the second row in my rootViewController, im removing the entire splitView and adding a new SplitView (based on my requirement), but if im in landscape mode, the app doesnt crash, when i turn my iPad in Potrait mode, when i click the button in the toolbar and in the popOver when i select the same second row in the rootView, the app is crashing.....hope u understood now....

How to get the frame (origin, Size) of every visible windows on the active space?

I'm trying to figure out how to get the frame of all visible windows.
I tried the following code, but it only works for the app itself other windows report {0,0,0,0}
NSArray *windowArray = [NSWindow windowNumbersWithOptions:NSWindowNumberListAllApplications | NSWindowNumberListAllSpaces];
for(NSNumber *number in windowArray){
NSLog(#"Window number: %#", number);
NSWindow *window = [[NSApplication sharedApplication] windowWithWindowNumber:[number intValue]];
NSLog(#"Window: %#", NSStringFromRect( [[window contentView] frame]));
}
Sample code is appreciated.
I figured it out:
NSMutableArray *windows = (__bridge NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
for (NSDictionary *window in windows) {
NSString *name = [window objectForKey:#"kCGWindowName" ];
CGRect bounds;
CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:#"kCGWindowBounds"], &bounds);
NSLog(#"%#: %#",name,NSStringFromRect(bounds));
}
You can't create an NSWindow for a window of another application. In general, you can't access the objects of other applications except through an interface that they cooperate with, like scripting.
You can get what you're looking for using the Quartz Window Services (a.k.a. CGWindowList) API.
I'm not at all sure that the window numbers returned by Cocoa are the same as the window numbers used by that API. In fact, the docs for -[NSWindow windowNumber] specifically say "note that this isn’t the same as the global window number assigned by the window server". I'm note sure to what use you can put the window numbers returned by +[NSWindow windowNumbersWithOptions:] which are not for your application's windows.

How to avoid double window opening at launch?

I've been porting my cocos2D iOS game to Mac and it works without problems but I don't understand why I get two windows open every time I launch the app.
One of them is the cocos2d window with the main menu scene and the properties and name I give but there is another blank white window with the app name (I mean the Xcode project name). I suppose this is a trivial issue but I really can't avoid that window from appearing.
What am I doing wrong?
This is my AppDelegate window initialization:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
CCDirectorMac *director = (CCDirectorMac*) [CCDirector sharedDirector];
//Posiciona ventana y define escalado
NSRect aFrame=[[NSScreen mainScreen] frame];
CGSize winSize = CGSizeMake(1024,768);
CC_DIRECTOR_INIT(winSize);
[self.window showsResizeIndicator];
[director setResizeMode:kCCDirectorResize_AutoScale];
[director setProjection:kCCDirectorProjection2D];
[window_ setContentAspectRatio:NSMakeSize(winSize.width,winSize.height)];
[window_ setStyleMask:[window_ styleMask] | NSResizableWindowMask | NSMiniaturizableWindowMask];
[window_ setTitle:#"Barman Hero"];
aFrame=[[NSScreen mainScreen] frame];
if (aFrame.size.width<=winSize.width || aFrame.size.height<=winSize.height) [window_ zoom:self];
[window_ center];
[glView_ setFrameSize:NSMakeSize(window_.frame.size.width,window_.frame.size.height-22)];
// Enable "moving" mouse event. Default no.
[window_ setAcceptsMouseMovedEvents:NO];
.....
.....
.....
//Carga escena principal
[[CCDirectorMac sharedDirector] runWithScene:[MainMenu scene]];
}
Thanks in advance.
It is likely that you have a Window defined in MainMenu.xib that is being opened semi-automatically. Remove the window from MainMenu.xib and any code that might reference it and it should no longer open the second window.

Resources