I have a UITableView with a custom cell and they are both for the iPad(size)
What is the best way to go? Should I create a new UITableView nib and a new Cell nib and call them or just resize them when needed?
Please also give me instructions how to either of these solutions :)
I created a new Cell nib only for the iPhone and in the VC of the tableview I checked if the app is running on an iPhone or iPad and called the right nib.
NSArray *objects;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
objects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell-iPad" owner:self options:nil];
}
else {
objects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell-iPhone" owner:self options:nil];
}
table views aren't generally used on their own on ipads due to them having a lot more space, generally the design pattern is to have a small table view along the left and a content area on the right. I believe there is a uisplitviewcontroller to handle this.
Related
First. IT WAS working until this last update from Apple. So in theory it should still work.
Here's the code:
CarouselViewController *cViewController = [[CarouselViewController alloc] initWithContent: edition];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: cViewController];
[self presentViewController: nav animated: YES completion:nil];
The reason i'm doing it is because i need this new window to be presented in fullscreen and not inside this ViewController (the caller) which is occupying half of the screen.
So, HOW can i fix this? And why BEFORE it was working and now with this silly iOS 9 update it isn't?
My guess (and that's all it is with the limited information presented) is that the root cause of the problem has something to do with CarouselViewController and it's view actually being loaded and presented on screen.
That is what is happening in your app during this line
[self presentViewController: nav animated: YES completion:nil]
I would set a breakpoint in that ViewController subclass loadView/viewDidLoad or check out it's Nib/Storyboard.
I have a UIViewController with UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate protocols. The UIViewController contains UITableView where I load some data from Core Data.
The loaded data include name, subtitle and an image.
They are set like:
cell.textLabel.text = [NSString stringWithFormat:#"%#", artist.title];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%# year", artist.year];
NSString *fileName = [NSString stringWithFormat: #"%#/%#", [[NSBundle mainBundle] resourcePath], artist.imageSmall];
cell.imageView.image = [UIImage imageWithContentsOfFile:fileName];
As I figured out before, [UIImage imageNamed:] caches the image which causes memory leaks. That's why I applied imageWithContentsOfFile method in code, where I needed to load big-size images. And it worked great. But it doesn't seem to work fine within my UITableView. Or I do smth wrong of cause :)
Here my images are not so heavy, they're like 20-40kb per image. It's ok even if I load 50 images per UITableView. It takes about 5Mb of memory to show, for example, 50 artists' photos per category. But what I noticed is that when I leave my ViewController and load it again via another indexPath (I open some other category cell and going to view the artists from that category) the memory used by app continues to increase. If I browse through 20 categories, then I get 100Mb memory usage. It doesn't look like the ARC work fine here.
So, how can I release the memory or destroy UITableView after moving back from my UIViewController?
2 hours later I found solution %)
I figured out to declare UITableView as (weak, nonatomic) instead of (strong, nonatomic).
And in ViewDidDisappear method I call
[self.tableView removeFromSuperview];
and memory releases successfully.
I'm converting my iPhone app to an iPad version, creating new XIBs for the iPad and rigging them to the existing objective C classes using the ~ipad XIB name.
In the iPhone version, I use the navigation controller to step backwards to the app. This should work just fine in the iPad too, but while the navigation controller does appear, it doesnt respond. In fact its invisible to any interaction, if theres a map behind the navigation controller and you double click back, you just zoom on the map where you clicked.
So I'm including a button in the iPad view which should do the same thing. On press I call a
[[self navigationController] popViewControllerAnimated: YES];
When I call this I get the EXC_BAD_ACCESS. I've gone in to the spooky zombie mode which gives me this
*** -[UIWindowLayer superlayer]: message sent to deallocated instance 0x83bb9f0
Ive determined that 0x83bb9f0 is the presenting layers self.view.layer
I'm using ARC to handle my allocations and deallocs.
THE QUESTION IS: How can I prevent self.view.layer from deallocing? or how can I allocate it again at the proper time so that I dont get this error?
I can provide more code if needed. Thanks so much!!
Edit: Heres where the main page (landing page) is created, and the nav controller
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
landingPage *LandingPage = [[landingPage alloc] initWithNibName:#"landingPage" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:LandingPage];
self.window.rootViewController = self.navigationController;
// [self.navigationController pushViewController:LandingPage animated:YES];
[self.window makeKeyAndVisible];
return YES;
Then here is where the inner view is called:
mapView *MapView = nil;
MapView =[[mapView alloc] initWithNibName:#"mapView" bundle:nil];
[self.navigationController pushViewController:MapView animated:YES];
So I got it!
The XIBs I was creating for the iPad version were windows instead of views. I recreated all of these as views and rigged it up and it worked just fine!
I am currently using XCode 3.2.3 and iOS4. I'm working on an app that simply starts with one screen and on a button click moves to the next.
I have gone thorugh the ViewController programming guide and a post here.
What I am doing is very similar to whats happening on the post. So let me explain the steps, I followed:
In IB, drag and drop, a View from the library into the editor. I renamed the new UIView to myView.
In my AppControllerDelegate, I added the new view "myView" as a property of the view controller (File's Owner). I synthesized it as well in the implementation.
Now, in the implementation of the ViewController, within the button pressed action handler, I wrote the following lines of code:
[self.view addSubView: myView];
On clicking the button however, I do not see a new screen or my new view. However if I do this, I get a new screen or new view:
UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame];
[self.view addSubView: anotherView];
I do know that the best way is to do it with separate NIBs for each UIView. However, I am new to iPhone development and have not explored that path as yet.
My question: What am I missing upto step 3?
One way you could be able to do it is by trying it this way
myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle: [NSBundle mainBundle]];
[self.view addSubview: myView.view];
Try that and see if it is working.. if yours is a view based project then instead of [self.view addSubview: myView.view], just give [self.view addSubview : myView];
I'm new in Xcode (and also here, in stack overflow) and I'm trying to build an application which contains a small UINavigationController (with a TableView inside) on the top of the window. So it should not be in full screen, it's just a little part of the GUI (just like a textField, or any other kind of component).
I've read that UINavigationController is designed to be displayed on the entire screen, but would it be possible to do it anyway?
If I can't, I'll probably have to write my own UINavigationController-like and TableViewController-like, with all transition effect (between 2 TableView) etcetera...
Thanks in advance for your help!
I founded the solution in a book and it's quite simple. I have to create the UINavigationViewController programmatically:
tableViewController = [[MyTableViewController alloc] initWithNibName:#"MyTableViewController" bundle:nil];
navCtrl = [[NavigViewController alloc] initWithRootViewController:tableViewController];
[navCtrl.view setFrame:CGRectMake(40, 40, 150, 200)];
[window addSubview:navCtrl.view];
[self.window makeKeyAndVisible];