[英]How to Print data from textfield present inside Tableview cell to console on tapping button
[英]How Do I Delete A Cell From My TableView By Tapping A Button On The Cell?
(我通过解析来管理笔记和帐户)我制作了一个笔记应用程序,该应用程序使用UITableView来显示您可以创建和编辑的笔记,任何创建帐户并登录的人都可以查看。(不要问我为什么我只是为了好玩而已),但是我的问题是我希望能够通过点击便笺上的“删除帖子”按钮来删除便笺: http : //imgur.com/rB4y7WB ,我已经用了最后两天了谷歌搜索试图找到答案,而我得到的只是带有如何滑动单元格以进行删除的教程的网站或视频,这不是我所需要的。
任何帮助将是巨大的!
希望这对您有用。
NSMutableArray *arrColor = [[NSMutableArray alloc] initWithObjects:@"White",@"Blue",@"Green",@"Yellow",@"Purple",@"Black", nil];
// UITableView DataSource Methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrColor count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifer = @"CustomCell";
CustomTableViewCell *objCustomCell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifer];
if (!objCustomCell) {
objCustomCell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
}
objCustomCell.btnDelete.tag = indexPath.row;
[objCustomCell.btnDelete addTarget:self action:@selector(actionDeleteBtn:) forControlEvents:UIControlEventTouchUpInside];
return objCustomCell;
}
-(void)actionDeleteBtn:(id)sender
{
UIButton *btn = (UIButton *)sender;
[arrColor removeObjectAtIndex:btn.tag];
[tblColorList reloadData];
}
谢谢 :)
您必须考虑两个问题,删除注释和从UITableView中删除单元格。 放置delete方法的最佳位置可能是在视图控制器中。 唯一的问题是如何告诉视图控制器删除哪个便笺。
您可以将delete方法设置为IBAction,将所有删除按钮附加到该按钮上,并使用其单元格正在显示的注释的索引标记每个按钮。 然后,在该方法中,检查按钮的标记并删除正确的注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.