код: проверить это:
#import <UIKit/UIKit.h>
@interface addsymptom : UITableViewController<UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *listData;
}
@property(nonatomic,retain)NSMutableArray *listData;
@end
data.m:
============
#import "CustomCell.h"
@implementation addsymptom
@synthesize listData;
- (void)viewDidLoad
{
self.navigationItem.title= @"Symptoms";
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"mainbg.png"]];
listData =[[NSMutableArray alloc] init];
[listData addObject:@"Backpain"];
[listData addObject:@"headache"];
[listData addObject:@"vomitting"];
[listData addObject:@"Bodypain"];
[listData addObject:@"thursday"];
[listData addObject:@"maleria"];
[listData addObject:@"Food poisioning"];
UIBarButtonItem *saveButton=[[UIBarButtonItem alloc]initWithTitle:@"save"
style:UIBarButtonSystemItemDone
target:self
action:@selector(save)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
[super viewDidLoad];
}
-(void)save {
[self.navigationController popViewControllerAnimated:YES];
}
- (UITableViewCell *)tableView:(UITableView *) tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload
{
self.listData = nil;
}
- (void)dealloc
{
[super dealloc];
}
@end
custom cell.h:
==========
#import <Foundation/Foundation.h>
@interface CustomCell :UITableViewCell {
IBOutlet UILabel *textLabel;
IBOutlet UIButton *bttn;
BOOL isChecked;
NSString *ans;
}
@property (nonatomic,retain) IBOutlet UILabel *textLabel;
@property (nonatomic,assign) BOOL isChecked;
@property(nonatomic,assign)IBOutlet UIButton *bttn;
-(void)checkBoxClicked:(id)sender;
@end
customcell.m:
==============
#import "CustomCell.h"
@implementation CustomCell
@synthesize textLabel,bttn,isChecked;
-(id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame ]) {
textLabel = [[UILabel alloc]init];
textLabel.textAlignment = UITextAlignmentLeft;
}
return self;
}
NSString *ABC=NULL;
NSString *xyz=NULL;
-(void)checkBoxClicked:(id)sender{
UIButton *tappedButton = (UIButton*)sender;
if([tappedButton.currentImage isEqual:[UIImage imageNamed:@"NotSelected.png"]]) {
[sender setImage:[UIImage imageNamed: @"IsSelected.png"] forState:UIControlStateNormal];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Message"
message:textLabel.text
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil,nil]autorelease];
[alert show];
ans = textLabel.text;
NSLog(@"%@",ans);
}
else {
[sender setImage:[UIImage imageNamed:@"NotSelected.png"]forState:UIControlStateNormal];
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)dealloc {
[super dealloc];
}
@end