【发布时间】:2014-09-10 13:57:02
【问题描述】:
我从包含乘客详细信息的服务器解析数据。 乘客详细信息保存到乘客类中。 主 viewController 包含一个 UITableView,它加载乘客数据并允许用户重新排列单元格的顺序。
我的问题是如何保存表格新订单并在每次应用程序启动时重新加载,但从服务器解析新乘客详细信息。 我不喜欢使用核心数据。
代码如下:
乘客.h
#import <Foundation/Foundation.h>
@interface Passenger : NSObject
{
NSString *name;
NSString *code;
NSString *country;
NSString *date;
}
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *code;
@property (nonatomic, strong) NSString *country;
@property (nonatomic, strong) NSString *date;
主视图控制器 m
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
NSString *stringToMove = passengersArray[sourceIndexPath.row];
[passengersArray removeObjectAtIndex:sourceIndexPath.row];
[passengersArray insertObject:stringToMove atIndex:destinationIndexPath.row];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Passenger *current = [passengersArray objectAtIndex:indexPath.row];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:101];
nameLabel.text = current.name;
UILabel *codeLabel = (UILabel *)[cell viewWithTag:102];
codeLabel.text = current.code;
UILabel *countryLabel = (UILabel *)[cell viewWithTag:103];
countryLabel.text = current.country;
return cell;
}
【问题讨论】:
标签: ios objective-c uitableview