2011-09-06 42 views
0

即時通訊學習Obj-C和即時通訊治療,使我的第一個「Hello world」文本的UITableView。啓動iphone。 UITableView你好世界與編輯按鈕失敗

我的問題是我無法在屏幕右側編輯按鈕顯示。這是我的代碼:

- (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)]; 
[email protected]"Hello World"; 
//[cell.textLabel setText:@"Hola2"]; 
return cell; 
} 

和:

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

我缺少的東西?

感謝您的幫助。

+0

這段代碼沒有問題,它工作正常。 – Ron

+0

如果你正在學習iPhone的開發,我強烈建議你[檢查出來](http://stackoverflow.com/questions/7296695/beginning-iphone-development-in-xcode-4/7296894#7296894)。 – rjgonzo

回答

4
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; 
} 
+0

哦,我的上帝,我覺得很愚蠢,我寫錯了方法,tyvm! –