iOS学习笔记--tableView中如何获取cell上textfiled的值
iOS学习笔记--tableView中如何获取cell上textfiled的值
最近在项目中遇到了这样一个问题,在tableView的cell上添加textfiled,然后获取cell上textfiled的值。cell的个数是可以动态改变的。如下图:
在网上看了很多别人写的没找见容易点的实现方法,自己写了一个比较笨的方法。主要代码如下:
@property(nonatomic,strong)NSMutableArray * arrray//数组中元素的个数为cell的行数
@property(nonatomic,strong)NSMutableArray * tmparrray;//存cell
@property(nonatomic,strong)NSMutableArray * tmpIndexPath;//存indexPath
@property(nonatomic,strong)NSMutableArray * tmparrayaaaaa;//获取cell的数据
在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中加入
[self.tmpIndexPath addObject:indexPath];
[self.tmparrray addObject:cell];
定义一个按钮,当点击按钮的时候获取cell上textfiled中所填的值。
for(int i = 0; i<self.tmpIndexPath.count; i++)
{
[self.tmparrayaaaaa removeObject:[NSString stringWithFormat:@"%id",i]];
cell= [self.tmpTableView cellForRowAtIndexPath:[self.tmpIndexPath objectAtIndex:i]];
[self.tmparrayaaaaa addObject:cell.tmpTextfiled.text];
for (int i = 0; i < ((self.arrray.count * (self.arrray.count +1)) /2 ) - self.arrray.count; i++)
{
[self.tmparrayaaaaa removeObjectAtIndex:0];
}
NSLog(@"======获取cell的值====>%@",self.tmparrayaaaaa);
主要思路:在点击取值按钮后根据indexpath来遍历cell ,然后将cell中textfiled得值存到tmparrayaaaaa数组中。因为i每次循环,textfiled的值毒药添加到数组中,所以数组终会有重复值,此时tmparrayaaaaa数组中元素的个数为(self.arrray.count * (self.arrray.count +1)) /2 ,故用循环的方式一次移除多余的元素。
原文地址
http://www.bieryun.com/2919.html

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
<iframe/onload=alert(document.cookie)></iframe>
frameLabelStart--frameLabelEnd
-
下一篇
Android TextView利用measureText自适应文本字体大小宽度
Android TextView利用measureText自适应文本字体大小宽度 常常有这种情况,UI设计师限定一个文本TextView的宽度值比如80dip,但是该文本长度很长,于是造成文本不能正常显示,针对这种长文本长度超过TextView自身限定宽度的情况,需要把字体大小自适应的调整小。例如xml写了两个同样宽度为80dp的TextView, <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="80dp" android:layout_height="wrap_content" android:backgroun...
相关文章
文章评论
共有0条评论来说两句吧...