【发布时间】:2014-02-24 21:34:44
【问题描述】:
我有 2 个数组,其中包含人们的名字,例如 John 或 Steve。第一个数组包含在我的服务器数据库中并且已经在使用我的应用程序的人。第二个数组包含用户通讯录中的人,但不在我的数据库中并且以前从未使用过我的应用程序。
现在当我在 UITableView 上显示这些名称时,它们都在一起,没有分离。
我需要在我的 UITableView 中创建 2 个不同的部分,每个数组一个部分。第一个数组的部分将称为“您通讯录中使用此应用的用户”,然后第二个数组的部分将称为“这些人还没有使用该应用”。
我基本上是在努力实现这张图片所显示的内容:http://appdupe.com/wp-content/uploads/2013/11/snapchat-clone-script-add.png
请注意有一个名为“Snapchat 上的朋友”的部分,然后是一个名为“从联系人中邀请朋友”的第二个部分。
如何为我的 UITableView 创建这些相同的“部分”?
以下是我用来设置表格视图的当前方法实现:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.potentiaFriendsFirstNamesArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"SettingsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSString *firstNameForTableView = [self.potentiaFriendsFirstNamesArray objectAtIndex:indexPath.row];
NSString *userNameForTableView = [self.potentiaFriendsUsernameArray objectAtIndex:indexPath.row];
[cell.textLabel setText:firstNameForTableView];
[cell.detailTextLabel setText:userNameForTableView];
return cell;
}
-(NSString*)stringBetweenString:(NSString*)start andString:(NSString *)end withstring:(NSString*)str
{
NSScanner* scanner = [NSScanner scannerWithString:str];
[scanner setCharactersToBeSkipped:nil];
[scanner scanUpToString:start intoString:NULL];
if ([scanner scanString:start intoString:NULL]) {
NSString* result = nil;
if ([scanner scanUpToString:end intoString:&result]) {
return result;
}
}
return nil;
}
【问题讨论】:
-
对您的图像示例的访问被拒绝。
-
对我来说很好用。在这里试试:i58.tinypic.com/rkt0qr.png
标签: ios objective-c arrays uitableview