TableView, обработать ошибку кликов - PullRequest
0 голосов
/ 02 апреля 2012

У меня есть пример проекта IOS, который я скачал из интернета. Этот проект представляет собой только табличное представление, заполненное именами. Когда вы нажимаете на имя, открывается диалоговое окно. Довольно просто Когда я пытаюсь переместить код в «основной проект» (приложение на основе 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

Спасибо:)

1 Ответ

0 голосов
/ 02 апреля 2012

Обычным подозрением в подобном случае является подключение выходов в кончике или, что еще более вероятно, подключение делегата tableView и источника данных в кончике.Можете ли вы проверить, что вы сделали это?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...