我已经在谷歌搜索很多次,但无法找到我正在寻找什么。 我在我的表格视图中有一个自定义单元格,其中有三个标签和一个删除按钮。现在我想删除我点击删除按钮的特定行。所以,我只想知道在delete按钮的ibAction方法中写入的代码是什么。提前致谢。如何在单击按钮时删除一个特定行?
这是我ViewController.m
#import "ViewController.h"
#import "detailObject.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.arrPeopleDetail = [[NSMutableArray alloc]init];
}
- (IBAction)submitButton:(id)sender {
if ([self.phoneTextField.text isEqualToString:@""] && [self.addressTextField.text isEqualToString:@""] && [self.phoneTextField.text isEqualToString:@""]) {
UIAlertView *alrt = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Fillup The Above Fields" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alrt show];
}
else if ([self.nameTextField.text isEqualToString:@""]) {
UIAlertView *alrt_name = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Plaeas Enter Name" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil ];
[alrt_name show];
}
else if ([self.addressTextField.text isEqualToString:@""]) {
UIAlertView *alrt_address = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter Address" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alrt_address show];
}
else if ([self.phoneTextField.text isEqualToString:@""]) {
UIAlertView *alrt_phoneNumber = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter Phone Number" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alrt_phoneNumber show];
}
else
{
detailObject *peopleDetail = [[detailObject alloc] init];
peopleDetail.strPeopleName = self.nameTextField.text;
peopleDetail.strPeopleAddress = self.addressTextField.text;
peopleDetail.strPeoplePhoneNumber = self.phoneTextField.text;
[self.arrPeopleDetail addObject:peopleDetail];
self.nameTextField.text = @"";
self.addressTextField.text = @"";
self.phoneTextField.text = @"";
}
[self.detailTable reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
UILabel *lbl1 = (UILabel*)[cell.contentView viewWithTag:1];
lbl1.text = [[self.arrPeopleDetail objectAtIndex:indexPath.row]valueForKey:@"strPeopleName"];
UILabel *lbl2 = (UILabel*)[cell.contentView viewWithTag:2];
lbl2.text = [[self.arrPeopleDetail objectAtIndex:indexPath.row]valueForKey:@"strPeopleAddress"];
UILabel *lbl3 = (UILabel*)[cell.contentView viewWithTag:3];
lbl3.text = [[self.arrPeopleDetail objectAtIndex:indexPath.row]valueForKey:@"strPeoplePhoneNumber"];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.arrPeopleDetail count];
}
- (IBAction)deleteButtonTapped:(id)sender {
[self.arrPeopleDetail removeLastObject];
[self.detailTable reloadData];
}
@end
哪里是你的删除按钮放在哪里?在Table视图中单元格? – 2015-02-23 07:26:09
是的,删除按钮放置在我的表格视图单元格中。 – Tirthendu 2015-02-23 07:29:40