问题
I'm new in iOS programming, and I want to do a simple thing. I saw several topics about my problem, but I don't understand why my code doesn't work...
- I created an empty view called details.xib
- I created an objective-C class, so I have two empty files details.h and details.m
- In my main view called ViewController.xib, I have a tableView
- In ViewController.m, I added on the top :
#import "details.h"
In ViewController.m, I modified the didSelectRowAtIndexPath method like this :
details *det = [[details alloc] init]; [self.navigationController pushViewController:det animated:YES];
I obtain this avertissement : Incomptatible pointer types sending 'details *__strong' to parameter of type 'UIViewController *'
Sorry if my english is awkward, I'm french... Thanks for your help !
回答1:
Check whether you are rooted the details.xib with class properly in file owner.
Refer this image:

And make sure you Details view controller is a sub class of UIViewController if not, create a view controller as UIViewController sub class(While creating a view controller itself u will can choose. refer below image)

回答2:
NSMutableArray *MenuArray=[[NSMutableArray alloc] init];
//Populate your array dynamically. Here I have populate my array with a custom object
[MenuArray addObject:[[GlobalMethod alloc] initWithMenuName:@"Home" WithNibNumber:1]];
[MenuArray addObject:[[GlobalMethod alloc] initWithMenuName:@"Profile" WithNibNumber:2]];
[MenuArray addObject:[[GlobalMethod alloc] initWithMenuName:@"Friends" WithNibNumber:3]];
[MenuArray addObject:[[GlobalMethod alloc] initWithMenuName:@"Photos" WithNibNumber:4]];
// And so on.....
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [MenuArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GlobalMethod *Method=[MenuArray objectAtIndex:[indexPath row]];
UITableViewCell *cell;
[cell setTag:[Method NibNumber]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
if([cell tag]==1)
{
//push to viewController1
}
else if([cell tag]==2)
{
//push to viewController12
}
else
{
//and go on
}
}
回答3:
Compiler is telling you : "I'm expecting some UIViewController
subclass in this presentViewController:animated:
method, and it's NOT"
detail
should indeed be a detailViewController
, subclassing UIViewController
.
EDIT
Go to your detail
class header files (detail.h), make sure it inherits from UIViewController :
@interface detail : UIViewController
//properties & methods declarations...
@end
来源:https://stackoverflow.com/questions/18959129/how-to-link-each-uitableviewcell-with-another-view