view.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *enterTF;
- (IBAction)addAct:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *addBtn;
@property (weak, nonatomic) IBOutlet UITableView *tableV;
@property NSMutableArray *ary;
@end
view.m
#import "ViewController.h"
@interface ViewController ()
{
NSInteger i;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableV.dataSource=self;
self.tableV.delegate=self;
_ary=[[NSMutableArray alloc]init];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)addAct:(id)sender {
// NSString *tempString = [[NSString alloc]initWithString:[_enterTF text]];
// [_ary addObject:tempString];
// [_tableV reloadData];
// NSLog(@"%@",_ary);
if ([self.addBtn.titleLabel.text isEqualToString:@"ADD"]) {
if (self.enterTF.text.length>0)
{
[_ary addObject:self.enterTF.text];
// self.tableV.delegate=self;
// self.tableV.dataSource=self;
[self.tableV reloadData];
NSLog(@"%@",_ary);
self.enterTF.text=@"";
}
}
else
{
if (self.enterTF.text.length>0) {
[_ary replaceObjectAtIndex:i withObject:self.enterTF.text];
// self.tableV.delegate=self;
// self.tableV.dataSource=self;
[self.tableV reloadData];
self.enterTF.text=@"";
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_ary count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"show"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"show"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text=[_ary objectAtIndex:indexPath.row];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
i=indexPath.row;
_enterTF.text=[_ary objectAtIndex:indexPath.row];
self.addBtn.titleLabel.text=@"Edit";
}
@end
Sign up here with your email
ConversionConversion EmoticonEmoticon