2011-12-17 44 views
0

HI我有一個UITableView,我有數據在我的數組中,我有search功能也在這裏。這是一個菜單類型的東西。有不同的菜餚和用戶可以搜索任何菜,在這裏左邊是一個文本字段,其文本爲0,當用戶搜索一些菜時,然後鍵入其他數字,然後如何將該輸入保存在正確的位置,因爲那時它的單元格index將與原來不同。你可以看到我的這張照片UITableView enter image description here如何在UITableView中設置按鈕的標題?

我知道這是一個邏輯問題,但請幫助我我卡在這裏。

+0

您需要發佈相關代碼以獲得有關此問題的合理幫助。 – PengOne 2011-12-17 18:37:43

+0

如果我理解它是正確的,你需要設置一個數組並重新加載數據,爲按鈕設置正確的值...... – 2011-12-17 19:04:58

回答

0

嘗試以下操作:

[button setTitle:@"title" forState:UIControlStateNormal];

+0

問題是,當某些用戶搜索某些東西時,其索引被改變 – Mashhadi 2011-12-18 16:40:40

0
  1. 起初採取的NSMutableArray

.h文件中

的NSMutableArray * searchDataArray;

現在申報其財產和合成它在你的.m文件

2.In您-(void)viewDidLoad頁頭搜索陣列,並保留它。

  1. [我在想,你可以設置搜索欄,並可以調用搜索委託] ..所以

    - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ 
    [sBar resignFirstResponder]; 
         searching = YES; //A boolean for searching condition 
    [searchData removeAllObjects]; 
    NSString *searchText = searchBar.text; 
    
    // record is a mutable array containing the cell text 
    int count = [records count]; 
    for (int i=0; i<count; i++) { 
    for(int j=0;j<6;j++){ 
    
        //finding the cell strings for checking 
        recordsstr = [NSString stringWithFormat:@"%@",[records objectAtIndex:i]; 
        //Matching string of table and search string 
    
    
        //case sensitivity checking 
        NSString *mainString = [NSString stringWithFormat:@"%@",[recordsstr lowercaseString]]; 
        NSString *searchString = [NSString stringWithFormat:@"%@",[searchText lowercaseString]]; 
        NSLog(@"main String: %@ and search string: %@ ",mainString,searchString); 
        NSLog(@"main string lenght: %d and search String lenght: %d",[mainString length],[searchString length]); 
        if([mainString isEqualToString:searchString] || [mainString rangeOfString:searchString].location != NSNotFound){ 
         [searchData addObject:[NSNumber numberWithInt:i]]; 
         NSLog(@"indext after matching: %d",i); 
         NSLog(@"number of date in searchdata array after matching: %d",[searchData count]); 
         break; 
        } 
        recordsstr = nil; 
    } 
    } 
    

在這段代碼我很匹配的單元格文本和文本搜索。找到單元格文本後,獲取單元格索引數組。

現在搜索完成後,再重裝你對你的tableview [tableview reloadData]

現在cellForRowAtIndex檢查

if(searching == YES){ 
for(int i = 0; i<[searchData count]; i++){ 
    if(indexPath.row is equal to [searchData objectAtIndex:i]) 
    { 
    //change your text field 
    } 
} 
else{ 
    //Without searching code 
    } 

可能它會幫助你。如果有任何問題我擊倒。

相關問題