मैं उद्देश्य-सी में नया हूं। मेरे पास एक पंक्ति है जिसमें 3 पंक्तियां और 1 खंड है। क्या आप बटन (एडसिटी) दबाकर टेबल में कुछ टेक्स्ट के साथ पंक्ति जोड़ने के लिए मेरी मदद कर सकते हैं?मैं तालिका में पंक्ति कैसे डाल सकता हूं?
- (void)viewDidLoad {
[super viewDidLoad];
m_bg.image = [UIImage imageNamed:[WeatherAppDelegate isNight] ? @"SettingsBackNight.png" : @"SettingsBackDay.png" ];
tableView.layer.cornerRadius = 10;
m_scrollView.layer.cornerRadius = 10;
[m_scrollView setContentSize:CGSizeMake(tableView.frame.size.width, tableView.frame.size.height)];
dataArray = [[NSMutableArray alloc] initWithObjects:@"Moscow", @"London", @"Paris", nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
[cell.textLabel setText: [dataArray objectAtIndex:indexPath.row]];
return cell;
}
-(IBAction)addCity:(id)sender
{
[dataArray addObject:@"City"];
NSArray *paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:[dataArray count]-1 inSection:1]];
[[self tableView] insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[tableView reloadData];
}
मुझे अपना कोड अपडेट किया गया है। यह काम नहीं करता है। – Sveta
मुझे insertRowsAtIndexPaths हटा दिया गया है और मेरा प्रोग्राम काम कर रहा है! – Sveta