2011-11-05 19 views
0

在tableview中,用戶可以點擊右上角的按鈕(導航欄版權所有),它會彈出自定義警報視圖並要求用戶輸入帶有兩個按鈕的edittext框取消並保存。正如你在下面的代碼中看到的那樣。當我點擊保存時,它會添加一行並顯示「標籤」以確認它正在工作,現在我希望能夠顯示用戶在框中鍵入的任何內容。我已經閱讀了所有的tableview蘋果開發者網站並且搜索了周圍,他們都沒有按照我想要的方式做。iphone:如何添加/插入從用戶輸入的字符串中的行自定義alertview

- (void) CustomAlertView:(CustomAlertView *)alert wasDismissedWithValue:(NSString *)value 
{ 
    [authorList addObject:@"label"]; 
    [tblSimpleTable reloadData]; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     // Delete the row from the data source. 
     [authorList removeObjectAtIndex:indexPath.row]; 
     [tblSimpleTable reloadData]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) 
    { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
     [authorList insertObject:@"label" atIndex:[authorList count]]; 
     [tblSimpleTable reloadData]; 
    } 
} 

UPDATE ***

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 

    if([title isEqualToString:@"Save"]) 
    { 
     NSString *any = [NSString stringWithFormat:@"'%@'"]; 
     [authorList addObject:any]; 
     [tblSimpleTable reloadData]; 
    } 
} 

插入行代碼

else if (editingStyle == UITableViewCellEditingStyleInsert) 
    { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
     NSString *any = [NSString stringWithFormat:@"'%@'"]; 
     [authorList insertObject:any atIndex:[authorList count]]; 
     //[authorList addObject:any]; 
     [tblSimpleTable reloadData]; 

    } 
} 

回答

1

去這個鏈接

http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html

在警報視圖委託methosü取值的文字

NSString * string = alertViews.textField.text;

然後重新加載表;

+0

謝謝,但只顯示如何創建自定義警報視圖。我已經有自定義警報視圖。我的問題是如何抓住框中鍵入的用戶數據並將其插入到tableview的行中。 – merrill

+0

嘗試上面的一個,它爲我工作正常 – Ron

+0

問題是authorList是類型NSMutableArray。我想添加用戶輸入數據到數組中,而不是NSString – merrill

相關問題