UISplitView crashing after selecting a row - xcode

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....

Related

UICollectionView iOS8 Wrong Offset

Surprisingly, after updating to iOS8 my app does not behave as in iOS7.
In particular, I made a calendar with UICollectionView. In iOS7 fine, the month cells were displayed correctly. But in iOS8...
I see an offset toward the top, that's the cells are shifted upward...I do not understand, really.... The code is very simple.
- (void)viewDidLoad
{
[super viewDidLoad];
UINib * nib = [UINib nibWithNibName:#"AgendaYearCollectionCell" bundle:[NSBundle mainBundle]];
[self.collectionView registerNib:nib forCellWithReuseIdentifier:agendaYearCellIdentifier];
[self.collectionView setDelegate:self];
[self.collectionView setDataSource:self];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 1;
[self.collectionView setCollectionViewLayout:layout];
}
The collection was not scrollable. If I make it scrollable, I can scroll and see the cells of the first row. But I do not want a scrollable collection.
I think the problem is in the inset. In fact, if I play with:
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(40, 2, 50, 60);
}
I can eventually get the first row again. But how to calculate the value for all the screen/devices? My app is landscape only and only for iPad.
What Apple changed?
Your Collection View has negative top offset. Providing more code could help, however let's try this first.
You called:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section
I would not call this unless you want different insets for different sections. It looks like you have only one section. I would configure it with Flow Layout:
flowLayout.sectionInset = CGSizeMake(40.0, 2.0, 50.0, 60.0);
I recommend to drop iOS 7 support, all devices with iOS 7 can be upgraded to 8.
how to calculate the value for all the screen/devices?
Should be the same offset for any iPad. Even if Apple will ship iPad with bigger screen, your offset will be the same. If you want Universal app with support for iPhone you could put device condition check and assign different numbers depending on the device paradigm.
Also, it could be something on the top. Did you messed with Navigation Bar? It doesn't clear from the picture.

UITextView setText should not jump to top in ios8

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.

NSTableView's frame inside a NSClipView/NSScrollView using auto layout

I'm trying to create a NSTableView inside a NSScrollView (the standard configuration, that is) in code, using auto layout. I can't figure out how to make this work.
Here's my loadView:
- (void)loadView
{
NSView *view = [[NSView alloc] init];
NSScrollView *tableScroll = [[NSScrollView alloc] init];
NSTableView *fileTable = [[NSTableView alloc] init];
[tableScroll setDocumentView:fileTable];
[tableScroll setHasVerticalScroller:YES];
[tableScroll setHasHorizontalScroller:NO];
fileTable.delegate = self;
fileTable.dataSource = self;
[fileTable setHeaderView:nil];
[fileTable setAllowsColumnReordering:NO];
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:#"column1"];
[fileTable addTableColumn:column];
[tableScroll setTranslatesAutoresizingMaskIntoConstraints:NO];
[fileTable setTranslatesAutoresizingMaskIntoConstraints:NO];
[view addSubview:tableScroll];
NSDictionary *topViews = NSDictionaryOfVariableBindings(tableScroll);
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[tableScroll]|" options:0 metrics:nil views:topViews]];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"|[tableScroll]|" options:0 metrics:nil views:topViews]];
self.fileTable = fileTable;
self.view = view;
}
What happens is that my table view's frame will be always equal to the bounds of the NSClipView. The view is inside a window and gets resized with it, and when I do that it'll resize the scrollview, the clip view and the table, but I can never scroll anywhere.
Looking at constraints I get, the NSScrollView gets constraints that set the clip view to fill it, the clip view has no constraints at all and the table view has a bunch of constraints related to the NSTableRowViews inside it.
If I add a constraint like |[fileTable(>=500)] to the clip view I'll get 500 pixels of NSTableView, but obviously I don't want to do that.
Even though this was answered by the poster in the comments above, I thought I’d put the answer here (having run into the same issue). If you are adopting auto layout, you would typically uncheck “Translates Mask Into Constraints” in the xib. However, for classes like NSScrollView and NSTableView, you should generally let them manage their own internal views by setting their translatesAutoresizingMaskIntoConstraints property to YES. It is still ok to set constraints that are external to these views, i.e. to resize in relation to their superview.
If you set translatesAutoresizingMaskIntoConstraints to NO, then you will need to supply constraints for all of the internal views, which unless you specifically need custom behavior (almost never), you will not want to do. This was the specific problem above.
An obvious side effect of not setting this correctly is that a table (for example) will not properly scroll beyond what is visible in the view.

UITabBar setSelectionIndicatorImage in iOS 4

i want know how i can use an image to the selected item in a UITabBar, in ios5 i'll do in this way:
[[myTabBar tabBar] setSelectionIndicatorImage:[UIImage imageNamed:#"TabBar_Activated.png"]];
but in iOS 4 that line give me an error, how i can do?
Try with this..
This will show the image when you select the tab...
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"selection-tab.png"]];
And this will set the image for tab bar...
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:#"Me" image:[UIImage imageNamed:#"tab-me.png"] tag:1];
//Set this tabitem in current view's tabBar.
[self setTabBarItem:tab1];

Weird font behavior on the NSTextField

I added programmatically NSTextField to my NSView:
NSTextField *projectLabel = [[NSTextField alloc] initWithFrame:frame];
[projectLabel setStringValue:#"projectName"];
[projectLabel setBezeled:NO];
[projectLabel setDrawsBackground:NO];
[projectLabel setEditable:NO];
[projectLabel setSelectable:NO];
[projectLabel setFont:[NSFont controlContentFontOfSize:13]];
projectLabel.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin;
[self addSubview:projectLabel];
[self setAutoresizesSubviews:NO];
This field was added correctly, but when I change size of view (or even move window to second display), font on field changes very weird (see attached image).
on start
after change of the size
I do not know what I did wrong
I drew this label on drawRect every time, when the size changes.
So, you're manually telling the field to display in its parent view's drawRect:?
Don't do that. It's a subview, so it'll get told to draw in its turn anyway. Just let that happen.

Resources