我有一个从互联网上下载的IOS示例项目。这个项目只是一个充满名字的tableview。单击名称时,将打开一个对话框。很简单。当我尝试将代码移动到我的“主项目”(基于TAB的应用程序)时,它无法工作。我在m和h文件中粘贴完全相同的代码。 它可能是我的布局文件中的东西吗?
#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
谢谢:)
答案 0 :(得分:0)
在这种情况下,通常的嫌疑人是在笔尖中连接插座,或者 - 甚至更可能 - 在笔尖中连接tableView委托和数据源。你能仔细检查一下,看看你做到了吗?