Iphone TableView数据';滚动时,s是否消失?
我尝试了这么多的例子,但都不起作用。请检查我的代码并给出解决方案。提前谢谢Iphone TableView数据';滚动时,s是否消失?,iphone,ios,objective-c,uitableview,Iphone,Ios,Objective C,Uitableview,我尝试了这么多的例子,但都不起作用。请检查我的代码并给出解决方案。提前谢谢 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdent
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
if (indexPath.section==0)
{
img=[UIButton buttonWithType:UIButtonTypeRoundedRect];
img.frame=CGRectMake(25, 15, 75, 75);
img.layer.cornerRadius=6.0;
img.clipsToBounds=YES;
img.layer.borderColor=[[UIColor grayColor]CGColor];
[img setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[cell.contentView addSubview:img];
[img addTarget:self action:@selector(takePic:) forControlEvents:UIControlEventTouchDown];
img.titleLabel.textColor=[UIColor blackColor];
text=[[UITextField alloc]initWithFrame:CGRectMake(105, 30, 200, 30)];
text.placeholder=@"Name";
[text setBorderStyle:UITextBorderStyleRoundedRect];
[cell addSubview:text];
[cell addSubview:img];
else if (indexPath.section==1)
{
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(20, 15, 100, 20)];
label.text=[dosageArray objectAtIndex:indexPath.row];
label.backgroundColor=[UIColor clearColor];
label.font=[UIFont boldSystemFontOfSize:15.0];
label.textColor=[UIColor blackColor];
[cell addSubview:label];
return cell;
}}
我在tableview中有三个部分。在第一部分中,我有一个textfield和imageview,如果我滚动textfield和imageview就会消失,这就是问题所在remove
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier]代码>来自else部件并留空
享受编程 试试这个:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Hello";
return cell;
谢谢。试试这个
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @""// value from your datasource
return cell;
}
解决方案1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
//your code
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"NameOFData ";
return cell;
}
解决方案2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text= @"YOUR TEXT";
}
希望这对你有帮助
祝你一切顺利 请尝试使用这个
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
return cell;
}
注意:如果数据有限,请使用解决方案-1,因为这不利于内存管理,其他方面的解决方案-2对您有好处。(解决方案-1可能对u有帮助)
解决方案-1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
//your code
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"NameOFData ";
return cell;
}
解决方案-2
编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
if (indexPath.section==0)
{
img=[UIButton buttonWithType:UIButtonTypeRoundedRect];
img.frame=CGRectMake(25, 15, 75, 75);
img.layer.cornerRadius=6.0;
img.clipsToBounds=YES;
img.layer.borderColor=[[UIColor grayColor]CGColor];
[img setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[cell.contentView addSubview:img];
[img addTarget:self action:@selector(takePic:) forControlEvents:UIControlEventTouchDown];
img.titleLabel.textColor=[UIColor blackColor];
text=[[UITextField alloc]initWithFrame:CGRectMake(105, 30, 200, 30)];
text.placeholder=@"Name";
[text setBorderStyle:UITextBorderStyleRoundedRect];
[cell addSubview:text];
[cell addSubview:img];
}
}
cell.textLabel.text = @"NameOFData ";
return cell;
}
尝试以下代码将NSMUTABLEARRY添加到all。此处显示的是NSMUTABLEARRY
text.text=[displayArray objectAtIndex:1];
深入解释…我不清楚,wt是else条件的用法>?如果(cell==nil)
这是真是假,那么这个的用法是什么。另外,您只是创建一个单元格并返回它。您在哪里分配数据?@iPatel谢谢..我在tableview中有一个三部分。在第一部分中,我有一个textfield和imageview,如果我滚动textfield和imageview将消失,这就是问题所在。您是否可以在此块中发布您的textfield和imageview添加的代码…..确定,然后尝试使用此UITableViewCell*cell=nil;静态NSString*CellIdentifier=@“Cell”;cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];返回单元@对于阿穆库德沙阿来说,这不会是一个问题。因为他总是在创造一个新的细胞不,这将是一个问题,因为他正在创造一个新的细胞,即使细胞不等于nilohhh!!我只是查看了一下您的代码,发现您已经在大括号中写入了返回单元格在大括号之后写入返回单元格。从其他角度看,表不会返回任何单元格将整个组件(imgaeView、textfield、.etch)放在中间…如果(cell==nil){cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1重用标识符:CellIdentifier];}。。。