Andreas Prang
Andreas Prang

Reputation: 2217

Get textField.text from custom UITableViewCell

I wrote a Special UITableViewCell. Now I need to get the text out of a textfield in

- (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

I hope there is anybody who knows a workaround.

Upvotes: 2

Views: 2042

Answers (3)

Michael Kessler
Michael Kessler

Reputation: 14235

I don't see any point in calling the cellForRowAtIndexPath, that builds the cell out of the data source (e.g. NSArray) and fills the cellText with text. And then access to the cellText property.

Just pull the needed text directly from the NSArray...

Upvotes: 0

Alex Reynolds
Alex Reynolds

Reputation: 96937

Cast it:

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

This should give you access to the cell's properties.

Upvotes: 8

Ole Begemann
Ole Begemann

Reputation: 135550

You should cast to your CustomCell type:

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

Upvotes: 1

Related Questions