2012-04-02 82 views
0

我有一个IOS示例项目,我从互联网上下载。这个项目只是一个充满名字的桌面视图。当你点击一个名字时,会打开一个对话框。很简单。当我尝试将代码移到我的“主项目”(基于TAB的应用程序)时,它不会工作。我在m和h文件中粘贴完全相同的代码。 它可能是我的布局文件中的东西?TableView,句柄点击错误

#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

问题不清楚。 – 2012-04-02 17:46:38

+0

正如已经评论的那样,“它不起作用”真的不能提供太多的暗示。我看到的第一件奇怪的事情是,您在实现TableViewViewController的同时导入了一个SecondViewController头,但是...... – 2012-04-02 17:52:21

回答

0

在这样的情况下,普通嫌疑犯在笔尖或挂钩网点 - 甚至更容易 - 在笔尖挂钩的tableView委托和数据源。你可以仔细检查一下,看看你做到了吗?