开发者

Detail button on second view

开发者 https://www.devze.com 2023-01-30 09:16 出处:网络
I am new to iOs programming and am having a hard time with the Navigation Controller. I have a table view which shows a detail-view when an item is selected.

I am new to iOs programming and am having a hard time with the Navigation Controller. I have a table view which shows a detail-view when an item is selected. The 'back' button appears correctly at the 开发者_高级运维top of the detail-view, so that is all fine.

Now I want to add a button to the detail view to link to a website. So I tried to add a button to the navigation controller. First I did it in IB, but if you do that it only appears in the first view and disappears in the detail view (and I only want to have it in the detail-view).

Then I tried it with code (added it in the detailviewcontroller in viedDidLoad:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(viewlink:)];

The button appears, and I added a function:

-(void)viewLink:(id)sender {
 NSLog(@"Went to view 2");
}

But when running the app I get the much quoted "-[ItemDetailViewController viewlink:]: unrecognized selector sent to instance 0x8a13cb0".

What would be the best way to do this? I have spend hours on this issue by now and am really pulling my hair out as it seems to be such a simple thing, so I must do something basic wrong.


In the error message, it says "viewlink:" (lowercase l) but your method is named viewLink: (uppercase L).

When calling that method, make sure you use the exact same spelling with the same case since the language is case-sensitive.

You should also have gotten a warning from the compiler (not a run-time error) saying "'ItemDetailViewController' may not respond to -viewlink:". Watch for and resolve all warnings.

The syntax highlighter will also give an indication that something's wrong. An unrecognized method will appear black but a recognized one will appear in light blue.

0

精彩评论

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