Начиная iphone. UITableView Привет мир с кнопкой редактирования не удается - PullRequest
0 голосов
/ 06 сентября 2011

Я изучаю Obj-C и собираюсь сделать свой первый UITableView с текстом "Hello world".

Моя проблема в том, что я не могу показать на экране правую кнопку редактирования. это мой код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:CellIdentifier] autorelease];
}
[[cell textLabel] setTextAlignment:(UITextAlignmentCenter)];
cell.textLabel.text=@"Hello World";
//[cell.textLabel setText:@"Hola2"];
return cell;
}

и

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.navigationItem.rightBarButtonItem=self.editButtonItem;
}

Я что-то упустил?

Спасибо за помощь.

1 Ответ

4 голосов
/ 06 сентября 2011
self.navigationItem.rightBarButtonItem=self.editButtonItem;

Это должно идти в viewDidLoad

Вы также правильно настраиваете строки и секции?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 1;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...