Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c iOS tableview单元格处理_Objective C_Cocoa Touch_Ios_Uitableview_Tableview - Fatal编程技术网

Objective c iOS tableview单元格处理

Objective c iOS tableview单元格处理,objective-c,cocoa-touch,ios,uitableview,tableview,Objective C,Cocoa Touch,Ios,Uitableview,Tableview,我有这段代码,其中“lineaRedToday”是一个UIImageView: - (void)viewDidLoad { [super viewDidLoad]; lineaRedToday = [UIImage imageNamed:@"line4.png"];} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { sta

我有这段代码,其中“lineaRedToday”是一个UIImageView:

- (void)viewDidLoad {

[super viewDidLoad];

lineaRedToday = [UIImage imageNamed:@"line4.png"];}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = @"tblCellView";

TableViewCell *cell = (TableViewCell*)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
    cell = tblCell;
}

cell.selectionStyle = UITableViewCellSelectionStyleNone;

[[lineDay objectAtIndex:currentTodaylineRed -1] setImage:lineaRedToday];


return cell;



- (IBAction) change{

    lineaRedToday = [UIImage imageNamed:@"linea.png"];
    [lineDay setImage:lineaRedToday];
    [myTableView reloadData];
}

这是一个具有15个自定义UITableViewCell的UITableView,我想在UIImageView中更改图像,此ImageView为“lineDay”,lineDay存在于所有单元格中,我想在所有单元格中更改其图像,但IBAction“change”仅在最后一个单元格中更改UIImageView,而根本不更改……为什么

是的,它将更改最后一个单元格中的图像,因为它只有最后一个单元格的引用,如果您想这样做,那么在CellForRowIndexPath中创建单元格时,请检查BOOL并根据该BOOL设置图像。同样在iAction中,更改BOOL值并调用表视图上的reloadData来重新加载它。作为-

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        static NSString *CellIdentifier                 = @"Test";

        UITableViewCell *cellView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cellView == nil) 
        {
            cellView = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

            UIImageView *bgImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 85.0f)];
            [bgImgView setTag:1];
            [bgImgView setBackgroundColor:[UIColor clearColor]];
            [cellView.contentView addSubview:bgImgView];
            [bgImgView release];
        }

        UIImageView *imgView = (UIImageView*)[cellView viewWithTag:1];

        if (buttonPressed) 
        {
            [imgView setImage:[UIImage imageNamed:@"listing_bg"]];
        }
        else 
        {
            [imgView setImage:[UIImage imageNamed:@"featured_listing_bg"]];
        }
        return cellView;
    }


- (IBAction) change{
    buttonPressed = !buttonPressed;
    [myTableView reloadData];
}

首先,lineaRedToday是一个
UIImage
,而不是
UIImageView
。第一个是图像,第二个是视图层次中的对象

然后,在代码中

if(cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
    cell = tblCell;
}
您可以使用
tblCell
。我看不出这是什么。您应该根据刚刚从nib加载的内容分配一些内容

我不知道什么是
lineDay
,但单个视图(即
UIImageView
)只能出现在一个单元格中,不能出现在多个单元格中。如果更改图像(
lineaRedToday
),仍需在视图中设置此新图像。应该是这样的

cell.yourImageView.image = linaRedToday;

配置单元格时。

我尝试使用在iAction中更改的bool,但它仅更改最后一个单元格