我需要将一个字符串值从 UItable 视图控制器传递给 UItable 视图单元
这是我在表视图控制器中使用的代码
#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
和我 TableViewController.m 有
- (void)viewDidLoad
{
[super viewDidLoad];
url=[NSURL URLWithString:urlstring];
urldata=[[NSString alloc]initWithContentsOfURL:url];
mutarray=[[NSMutableArray alloc]init];
self.mutarray=[urldata JSONValue];
NSDictionary *dict=[mutarray objectAtIndex:0];
self.title=[dict valueForKey:@"category"];
}
- (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] autorelease];
}
cell.custurlstring=urlstring;
NSLog(@"%@", cell.custurlstring);
return cell;
}
在我的自定义 Tableviewcell.h 中有
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell{
NSString *custurlstring;
}
@end
我的自定义 Tableviewcell.m 有
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
NSLog(@"%@",custurlstring);
}
return self;
}
现在我通过使用 NSLog 获得了 tableviewcontroller 中的字符串内容..但是如果我尝试在 TableViewCell 中打印值,我无法获得这些值...请指导...