2013-04-10 122 views
0

我想要獲得一個添加按鈕來添加行到一個表,然後可以編輯 我得到預期的標識符或'('行10, 17,和30以下是代碼:期望的標識符或'('在xcode 4.6.1

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
    UILabel *lblName = (UILabel *)[cell viewWithTag:100]; 
    [lblName setText:[intervalArray objectAtIndex:[indexPath row]]]; 
    return cell; 
} 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:CellIdentifier]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
} 


if ([indexPath section]) == 0 { 
    UITextField *workoutTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; 
    workoutTextField.adjustsFontSizeToFitWidth = YES; 
    workoutTextField.textColor = [UIColor blackColor]; 
    if ([indexPath row] == 0) { 
     workoutTextField.placeholder = @"..."; 
     workoutTextField.keyboardType = UIKeyboardTypeEmailAddress; 
     workoutTextField.returnKeyType = UIReturnKeyNext; 

}} 

// Configure the cell... 

return cell; 

我已經試過你的建議,他們擺脫了所有的錯誤,但我仍然無法行與按鈕添加到我的餐桌任何建議。關於如何添加行到表中將不勝感激,這是我的第一個iOS應用程序,並且對於編程來說我是相當新的。感謝所有的幫助! 我正在使用OS X 10.8.3

回答

3

我覺得你在這裏放錯一個括號:

if ([indexPath section]) == 0 { 

你的意思是:

if ([indexPath section] == 0) { 

方括號在這裏被包圍方法調用消息發送給indexPath;圓括號包含條件比較您正在進行的操作是檢查調用[indexPath section]的結果是否等於零。

編輯:你也可以有一個右大括號太快 - 第7行的}關閉你的方法-tableView:cellForRowAtIndexPath:的整個實施。您可能希望將其一直移動到您的return cell;聲明之下。

+0

是的......你找到答案:) +1 – 2013-04-10 18:43:12

1

第10行和第17行的條件和第30行的return語句屬於哪種方法?它們似乎卡在你的實現文件中,這使編譯器感到困惑。

簡單地移動結束-tableView:cellForRowAtIndexPath:的大括號將修復錯誤,但由於您正在返回第7行的值(結束方法的執行),所以其餘代碼將不會執行任何操作。

相關問題