2010-07-01 63 views
2

我寫了一個特殊的UITableViewCell。現在我需要獲取文本從一個文本框的從自定義UITableViewCell獲取textField.text

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
CustomCell *custumCell = [tableView cellForRowAtIndexPath:indexPath]; 
    //warning: incompatible Objective-C types initializing 'struct UITableViewCell *', expected 'struct CustomCell *' 

NSString *title = [custumCell cellTitle].text; 
[self setArticleReaded:title]; 
[title release]; 

}

#import <UIKit/UIKit.h> 


@interface CustomCell : UITableViewCell { 
    IBOutlet UILabel *cellTitle; 
    IBOutlet UILabel *cellSubTitle; 
    IBOutlet UILabel *cellPubDate; 
} 

@property (nonatomic, retain) IBOutlet UILabel *cellTitle; 
@property (nonatomic, retain) IBOutlet UILabel *cellSubTitle; 
@property (nonatomic, retain) IBOutlet UILabel *cellPubDate; 

@end 

我希望有任何人誰知道一種解決方法。

回答

8

投它:

CustomCell *custumCell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 

這應該給你訪問到細胞的特性。

1

你應該投放到您的CustomCell類型:

CustomCell *custumCell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 
0

我沒有看到調用cellForRowAtIndexPath的任何一點,它從數據源(例如NSArray)中構建單元格並用文本填充cellText。然後訪問cellText屬性。

只需從NSArray中直接提取所需文本...