开发者

Ironically Pushing Blank View Controllers

this is my first post on here, though with the help of many questions and answers from members of this community, I have brought my project to near completion.

I have read multiple threads similar to what I'm asking, but the methods were completely different. No code has worked so far.

Basically (I say this because my code involves a lovely snake-like descent into a complicated mess, but applicable snippets will be put up upon request), my problem is that I'm calling

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

and it pushes my viewcontroller in the simulator and NSLogs the string I need changed beautifully, but it pushes a blank view! The code for that run makes the view controller variable a constant:

UIViewController *viewController = [[xSheetMusicViewController alloc]initWithNibName:nil bundle:nil];

So I thought to myself, what am I doing!? So I went back to the old method, which involved making the UIViewcontroller an if-then, if-else-then statement that would push different views depending on whether certain rows were selected (standard stuff). Which pushed a new view with my string loaded perfectly, but it only NSLog'ed one string over and over! And the worst part was the my app would call either SIGABRT, or EXC_BAD_ACCESS when I tried returning to the rootviewcontroller. (here's the applicable code):

UIViewController *viewController = [[[UIViewController alloc]init]autorelease];
if (indexPath.row == 0 && indexPath.se开发者_如何学编程ction == 0) {
    appDelegate.baseURL = @"mussette.pdf";
viewcontroller = [[xSheetmusicViewController alloc]initwithnibname:nil bundle:nil];
}
else if (...)
//pushview, changestring, blah blah//

Now, I would prefer that my view push the PDF like it's supposed to, and have the correct string value (and not give me SIGABRT or EXC_BAD_ACESS, but those are givens), but it seems that compromise is just out of my reach. I know there's probably something stupid I'm doing that could be solved with one line of code, but for now, it seems hopeless.

Thanks in advance.

EDIT: To answer all of your questions, yes, there is no xib, rather an (id)init method in the next view.

EDIT 2: to answer lostInTransit's request and add some additional details:

<else if (indexPath.row == 1 && indexPath.section == 0) {
    appDelegate.baseURL = @"Importing PDF's.pdf";

Also, if it helps, the output keeps logging: Application tried to push a nil view controller on target .

When I try to push the view from a tableviewcell, and it did that before when it loaded the PDF right so I ignored it.


Question: why do you first initialize your viewController as a UIViewController and then again as xSheetmusicViewController? I think the problem is with releasing values properly. In one init, you do an autorelease, in the other you don't. So chances are you are releasing a variable twice leading to the BAD ACCESS.

Do you mind posting the "blah blah" :) in the last piece of code?


Do you have a file named xSheetmusicViewController.xib in your application? That will be loaded with your view controller as its owner after you call [[xSheetmusicViewController alloc] initNithNibName:nil bundle:nil]; (it will actually be loaded when the view property is first accessed). If that file doesn’t exist, then the view controller’s -loadView: method will be called to load its view.

If you have a blank view, either you have a blank or mis-named nib (perhaps you renamed the class but not the nib?) or you aren’t creating the right view in -loadView:.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜