小编Vja*_*del的帖子

使用Section UITableView按字母顺序对联系人排序

我有一个NSMutableArray:self.contact带有对象(名称按字母顺序排序):

(
    "Anna Haro",
    "Cheesy Cat",
    "Daniel Higgins",
    "David Taylor",
    "Freckles Dog",
    "Hank Zakroff",
    "John Appleseed",
    "Kate Be\U00e9ll"
)
Run Code Online (Sandbox Code Playgroud)

我用这行代码成功地在右边显示了字母:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
        return[NSArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", nil];
    }
Run Code Online (Sandbox Code Playgroud)

现在,我要实现允许我访问好部分的方法?

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index {

}
Run Code Online (Sandbox Code Playgroud)

也许我要改变numberOfSections?这是我的代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1
}
Run Code Online (Sandbox Code Playgroud)

下一个 :

我做了两个阵列NSArray …

objective-c uitableview ios sectionindexer

7
推荐指数
1
解决办法
6102
查看次数

UICollectionView didSelectRowAtIndexPath不起作用

didSelectRowAtIndexPath方法在我的应用中无效.我不打印任何输出NSLog:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    PFObject *imageObject = [self.imageFilesArray objectAtIndex:indexPath.row];
    PFFile *imageFile = [imageObject objectForKey:@"file"];
    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            cell.imageView.image = [UIImage imageWithData:data];

        }
    }];

    return cell;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

        PhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSLog(@"didSelectRowAtIndexPath");
    cell.imageView.image = self.image;
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

我希望当我点击一个单元格时,选择图像并将图像赋予self.image.

我们能用segue做到吗?因为我的didSelectRowAtIndexPath方法根本不起作用.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showPhotoDetail"]) { …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview

6
推荐指数
1
解决办法
2万
查看次数

使用NSObject过滤NSArray

我想在tableView中使用searchbar.我有一个带有人的NSArray(NSObject).在cellForRow中,我正在使用此代码:

Person *person = [[self.sectionedPersonName objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.textLabel.text = person.fullName;
Run Code Online (Sandbox Code Playgroud)

并为searchBar这段代码:

- (void)searchForText:(NSString *)searchText {
    if (searchText.length > 0) {
        searchBar = YES;
    } else {
        searchBar = NO;
    }
        NSLog(@"%@", self.sectionedPersonName);
        NSPredicate *predicate; = [NSPredicate predicateWithFormat:@"SELF.fullName beginswith[c] %@", searchText];
        self.searchResults = [self.sectionedPersonName filteredArrayUsingPredicate:predicate];
}
Run Code Online (Sandbox Code Playgroud)

self.sectionedPersonName 包含这个:

(
        (
        "<Person: 0x7fc0f6012650>"
    ),
        (
    ),
        (
    ),
        (
        "<Person: 0x7fc0f600f8a0>",
        "<Person: 0x7fc0f60132e0>"
    ),
        (
    ),
        (
    ),
        (
    ),
        (
        "<Person: 0x7fc0f6012d80>"
    ),
        (
    ),
        (
        "<Person: 0x7fc0f6012b30>"
    ),
        (
        "<Person: …
Run Code Online (Sandbox Code Playgroud)

objective-c uisearchbar nsarray nspredicate ios

1
推荐指数
1
解决办法
186
查看次数