Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Iphone 在ios中将数据从UItableviewController传递到UItableViewcell_Iphone_Ios_Xcode_Uitableview - Fatal编程技术网

Iphone 在ios中将数据从UItableviewController传递到UItableViewcell

Iphone 在ios中将数据从UItableviewController传递到UItableViewcell,iphone,ios,xcode,uitableview,Iphone,Ios,Xcode,Uitableview,我需要将字符串值从UItable View控制器传递到UItable View单元格 这是我使用的代码 在我的表视图控制器中 #import <UIKit/UIKit.h> #import "CustomCell.h" @interface DetViewController : UITableViewController { NSString *urlstring; CustomCell *cust; } @property(nonatomic,retain)NSStrin

我需要将字符串值从UItable View控制器传递到UItable View单元格

这是我使用的代码 在我的表视图控制器中

#import <UIKit/UIKit.h>
#import "CustomCell.h"

@interface DetViewController : UITableViewController
{
NSString *urlstring;

CustomCell *cust;

}

@property(nonatomic,retain)NSString *urlstring;
@property(nonatomic,retain)NSMutableArray *mutarray;

@property(nonatomic,retain)CustomCell *cust;
@end
在我的自定义Tableviewcell.h中

#import <UIKit/UIKit.h>

@interface CustomCell : UITableViewCell{
NSString *custurlstring;


}
@end
现在,我使用NSLog在tableviewcontroller中获取字符串内容。但是如果我尝试在TableViewCell中打印值,我无法获取这些值。。。
请提供指导…

您应该在委托方法-(UITableViewCell*)tableView:(UITableView*)tableView CellforRowIndexPath:(NSIndexPath*)indexPath中执行此操作

你可以这样写:

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {        
    cell = [[CustomCell alloc] initWithStyle:<style enum value> reuseIdentifier:reuseIdentifier string:urlstring]
    //cell.mystring = self.mystring;
}

return cell;
}

您应该在委托方法-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath中执行此操作

你可以这样写:

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {        
    cell = [[CustomCell alloc] initWithStyle:<style enum value> reuseIdentifier:reuseIdentifier string:urlstring]
    //cell.mystring = self.mystring;
}

return cell;
}

您需要在
cellforrowatinexpath:
中设置单元格,然后在此方法中设置单元格上的字符串。当您创建
UITableViewController
时,此方法已提供给您

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.custurlstring = urlstring;
    return cell;
}

您需要在
cellforrowatinexpath:
中设置单元格,然后在此方法中设置单元格上的字符串。当您创建
UITableViewController
时,此方法已提供给您

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.custurlstring = urlstring;
    return cell;
}

无需自定义单元格以在其上显示图像和标签, 只需将它们添加到普通单元格中即可

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

static NSString *CellIdentifier = @"MyCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {        
    cell = [[CustomCell alloc] initWithStyle:<style enum value> reuseIdentifier:reuseIdentifier string:urlstring]
    //cell.mystring = self.mystring;
}

// customize your image and your labels here with rects here


UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yourimage.png"]];
    [cell.contentView addSubview:image];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(your rect here)];
[cell.contentView addSubview:label];

return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“MyCell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[CustomCell alloc]initWithStyle:reuseIdentifier:reuseIdentifier字符串:urlstring]
//cell.mystring=self.mystring;
}
//在此处使用矩形自定义图像和标签
UIImageView*image=[[UIImageView alloc]initWithImage:[UIImageName:@“yourimage.png”];
[cell.contentView addSubview:image];
UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(此处为您的rect)];
[cell.contentView addSubview:label];
返回单元;
}

无需自定义单元格来显示图像和标签, 只需将它们添加到普通单元格中即可

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

static NSString *CellIdentifier = @"MyCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {        
    cell = [[CustomCell alloc] initWithStyle:<style enum value> reuseIdentifier:reuseIdentifier string:urlstring]
    //cell.mystring = self.mystring;
}

// customize your image and your labels here with rects here


UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yourimage.png"]];
    [cell.contentView addSubview:image];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(your rect here)];
[cell.contentView addSubview:label];

return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*CellIdentifier=@“MyCell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[CustomCell alloc]initWithStyle:reuseIdentifier:reuseIdentifier字符串:urlstring]
//cell.mystring=self.mystring;
}
//在此处使用矩形自定义图像和标签
UIImageView*image=[[UIImageView alloc]initWithImage:[UIImageName:@“yourimage.png”];
[cell.contentView addSubview:image];
UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(此处为您的rect)];
[cell.contentView addSubview:label];
返回单元;
}


您可以在init函数中打印custurl,但随后会添加值。即使我尝试在init函数中打印,它也会返回null…如果我尝试在tableviewcontroller中打印该cust url值,它会显示null..这意味着没有将值分配给custurl right?。尝试添加属性:@property(非原子,retain)NSString*custurlstring;在您的CustomCell声明中。并检查初始表视图字符串是否有值…我是通过NSLog(@“%@”,cell.custurlstring)使用命令获得的;在表视图控制器中..但如果我试图在自定义tableviewcell中打印它,它将无法获得..我已声明aas NSLog(@“%@”,custurlstring);您可以在init函数中打印custurl,但以后会添加值。即使我尝试在init函数中打印,它也会返回null…如果我尝试在tableviewcontroller中打印该cust url值,它会显示null..这意味着没有将值分配给custurl right?。请尝试添加属性:@property(nonatomic,retain)NSString*custurlstring;在您的CustomCell声明中。并检查初始表视图字符串是否有值…我是通过NSLog(@“%@”,cell.custurlstring)使用命令获得的;在表视图控制器中..但如果我试图在自定义tableviewcell中打印它,它将无法获得..我已声明aas NSLog(@“%@”,custurlstring);因为您正在
初始化期间记录它。从该方法中可以看出,在单元格初始化之前,不会设置字符串。添加
NSLog(@“%@”,cell.custurlstring)
就在cell.custurlstring=urlstring的下方因此,如果我尝试在自定义TableViewcell中实现,我必须初始化为cell.custurlstring还是custurlstring…?我是通过NSLog(@“%@”,cell.custurlstring)使用您的命令获得的;在表视图控制器中..但如果我试图在自定义tableviewcell中打印它,它将无法获得..我已声明aas NSLog(@“%@”,custurlstring);它在您的
UITableViewCell
中显示为null,因为您试图在
init
期间记录它。它在初始化时不存在。它是在单元格初始化后设置的。将它记录在
drawRect:
方法中,它就会显示出来。也许你应该考虑从默认的单元格开始,熟悉 UITababyVIEW/CODE >,然后移到实现自定义单元格上,因为你在 init < />代码中记录它。从该方法中可以看出,在单元格初始化之前,不会设置字符串。添加
NSLog(@“%@”,cell.custurlstring)
就在cell.custurlstring=urlstring的下方因此,如果我尝试在自定义TableViewcell中实现,我必须初始化为cell.custurlstring还是custurlstring…?我是通过NSLog(@“%@”,cell.custurlstring)使用您的命令获得的;在表视图控制器中..但如果我试图在自定义tableviewcell中打印它,它将无法获得..我已声明aas NSLog(@“%@”,custurlstring);它在您的
UITableViewCell
中显示为null,因为您试图在
init
期间记录它。它在初始化时不存在。正在设置