मैंने अस्थायी रूप से UITableViewCell
प्रोग्रामेटिक रूप से कुछ मान जोड़े। लेकिन मुझे प्रत्येक सेल में छवियों को जोड़ने की जरूरत है। मैं उसे कैसे कर सकता हूँ?UITableView सेल में छवियों को कैसे जोड़ा जाए?
मेरा कोड यहां है। ज फाइल
@interface BidalertsViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> {
NSArray *listData;
}
@property(nonatomic, retain) NSArray *listData;
@end
मीटर फ़ाइल
@synthesize listData;
- (void)viewDidLoad {
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(5,0,310,28)];
newView.backgroundColor=[UIColor whiteColor];
UITextView *mytext = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 25.0)];
mytext.backgroundColor = [UIColor clearColor];
mytext.textColor = [UIColor blackColor];
mytext.editable = NO;
mytext.font = [UIFont systemFontOfSize:15];
mytext.text = @"Asset Name";
[mytext release];
[newView addSubview:mytext];
[self.view addSubview:newView];
[newView release];
NSArray *array = [[NSArray alloc] initWithObjects:@"iPhone", @"iPod", @"iPad",nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[listData dealloc];
[super dealloc];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imv.image=[UIImage imageNamed:@"user.jpg"];
[cell.contentView addSubview:imv];
[imv release];
}
@end
कोड सेल करने के लिए छवियों को जोड़ नहीं था। समस्या क्या है? सेल में कस्टम छवि जोड़ने के लिए मैं कैसे कर सकता हूं? अपने - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
विधि में
cell.imageView.image = [UIImage imageNamed:@"user.jpg"];
:
छवि प्रदर्शित होती है। लेकिन छवि पाठ के सामने प्रदर्शित होती है। पाठ पूरी तरह से नहीं दिखाया गया है। –
यह ठीक से काम करता है क्योंकि 'टेक्स्ट लेबल' में फ्रेम है जो आपके 'UIImageView' के साथ छेड़छाड़ करता है। शायद आपको कस्टम सेल की आवश्यकता है। – beryllium