Iphone TableView,句柄单击错误
我有一个IOS示例项目,是我从互联网上下载的。此项目只是一个填充了名称的tableview。单击名称时,将打开一个对话框。很简单。当我试图将代码转移到我的主项目时,一个基于选项卡的应用程序是行不通的。我在m和h文件中粘贴了完全相同的代码。 可能是我的布局文件里的什么东西吗Iphone TableView,句柄单击错误,iphone,ios,Iphone,Ios,我有一个IOS示例项目,是我从互联网上下载的。此项目只是一个填充了名称的tableview。单击名称时,将打开一个对话框。很简单。当我试图将代码转移到我的主项目时,一个基于选项卡的应用程序是行不通的。我在m和h文件中粘贴了完全相同的代码。 可能是我的布局文件里的什么东西吗 #import "SecondViewController.h" @implementation TableViewViewController @synthesize tableViewArray; - (void)ta
#import "SecondViewController.h"
@implementation TableViewViewController
@synthesize tableViewArray;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *message = [NSString stringWithFormat:@"%@",[tableViewArray objectAtIndex:indexPath.row]];
NSString *focus = [NSString stringWithFormat:@"Focus"];
if ([focus isEqualToString:message]) {
// ...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message: message delegate:self cancelButtonTitle:@"Sebastian :)" otherButtonTitles:nil];
[alert show];
[alert release];
}
//NSString *message = [NSString stringWithFormat:@"You selected %@",[tableViewArray objectAtIndex:indexPath.row]];
/*NSString *message = [NSString stringWithFormat:@"You selected %@",[tableViewArray objectAtIndex:indexPath.row]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message: message delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
[alert show];
[alert release];*/
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableViewArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableIdentifier"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SimpleTableIdentifier"]autorelease];
}
cell.textLabel.text = [tableViewArray objectAtIndex:indexPath.row];
return cell;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *array = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4 ",@"5",@"6",@"Sko-7",@"",@"8",@"9",nil];
self.tableViewArray = array;
[array release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
谢谢:在这种情况下,通常的嫌疑犯是在nib中连接插座,或者更可能是在nib中连接tableView委托和数据源。你能仔细检查一下你是否这样做了吗?如前所述,它不起作用,实际上并没有给出太多的提示。我看到的第一件奇怪的事情是,在实现TableViewController时导入了SecondViewController头,但是。。。。