0

我现在遇到了一个大问题,因为我的更新按钮根本没有检测到由于回收而被选中的行!尝试标记按钮,但它也没有检测到正确的按钮。请帮忙!我已经坚持了好几天了。如果没有,请随意推荐除标记之外的其他更好的解决方案。我通过 NSDictionary 解析部分和行,如下所示:

"15/08/2012" =     (
            {
        BIBNo = 290408;
        date = "15/08/2012";
        itemSequence = 000010;
        name = "Sams teach yourself iPhone application development in 24 hours / John Ray.";
        noOfRenewal = 3;
        number = 000290408;
        status = "Normal Loan";
        time = "24:00";
        type = Loans;
    }
);
"16/08/2012" =     (
            {
        BIBNo = 187883;
        date = "16/08/2012";
        itemSequence = 000010;
        name = "Positive thinking / Susan Quilliam.";
        noOfRenewal = 3;
        number = 000187899;
        status = "Normal Loan";
        time = "24:00";
        type = Loans;
    },
            {
        BIBNo = 161816;
        date = "16/08/2012";
        itemSequence = 000010;
        name = "Malaysian Q & As / compiled by Survey & Interview Department ; illustrations by Exodus.";
        noOfRenewal = 1;
        number = 000161817;
        status = "Normal Loan";
        time = "24:00";
        type = Loans;
    }
);
"17/08/2012" =     (
            {
        BIBNo = 187882;
        date = "17/08/2012";
        itemSequence = 000010;
        name = "Increasing confidence / Philippa Davies.";
        noOfRenewal = 1;
        number = 000187907;
        status = "Normal Loan";
        time = "24:00";
        type = Loans;
    },
            {
        BIBNo = 244441;
        date = "17/08/2012";
        itemSequence = 000010;
        name = "Coach : lessons on the game of life / Michael Lewis.";
        noOfRenewal = 2;
        number = 000244441;
        status = "Normal Loan";
        time = "24:00";
        type = Loans;
    },
            {
        BIBNo = 291054;
        date = "17/08/2012";
        itemSequence = 000010;
        name = "iPhone application development for IOS 4 / Duncan Campbell.";
        noOfRenewal = 3;
        number = 000291054;
        status = "Normal Loan";
        time = "24:00";
        type = Loans;
    }
);

}

我的代码cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"Cell";
UserCustomCell *cell = (UserCustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.bookTitle.frame = CGRectMake(12, 0, 550, 40);

if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"UserCustomCell" owner:self options:nil];
    cell = userCustomCell;
    self.userCustomCell = nil;
}

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    cell.bookTitle.frame = CGRectMake(12, 0, 550, 40);
    cell.renewButton.frame = CGRectMake(600, 14, 68, 24);
}
[cell.renewButton useBlackActionSheetStyle];

dataSource = [[NSMutableDictionary alloc] init]; // This would need to be an ivar

for (NSDictionary *rawItem in myArray) {
    NSString *date = [rawItem objectForKey:@"date"]; // Store in the dictionary using the data as the key

    NSMutableArray *section = [dataSource objectForKey:date]; // Grab the section that corresponds to the date

    if (!section) { // If there is no section then create one and add it to the dataSource
        section = [[NSMutableArray alloc] init];
        [dataSource setObject:section forKey:date];
    }
    [section addObject:rawItem]; // add your object
}
self.dataSource = dataSource;
NSLog(@"Data Source Dictionary: %@", dataSource); 

NSArray *sections =[[dataSource allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSString *sectionTitle = [sections objectAtIndex:indexPath.section];

NSArray *items = [dataSource objectForKey:sectionTitle];

NSDictionary *dict = [items objectAtIndex:indexPath.row];
cell.bookTitle.text = [dict objectForKey:@"name"];
cell.detail.text = [NSString stringWithFormat:@"Due Date: %@ Due Time: %@", 
                    [dict objectForKey:@"date"], [dict objectForKey:@"time"]];


cell.renewButton.tag = indexPath.row;
return cell;   

}

现在的样子:

非常感谢!

4

1 回答 1

0

我通过在@Phillip 推荐的数组中添加索引解决了这个问题,如下所示:

for (int a = 0; a < myArray.count; a++){

    NSMutableDictionary *mDict = [myArray objectAtIndex:a];
    NSNumber *myIndex = [NSNumber numberWithInt:a];
    [mDict setValue:myIndex forKey:@"index"];
    NSLog(@"added index: %@", myArray);
}
self.myArray = myArray;

在我在按钮中设置标签之前,它会检测到正确的项目。

 NSString *index = [dict objectForKey:@"index"];
NSInteger index_tag = (@"%d", [index intValue]);
NSLog(@"%d", index_tag);
cell.renewButton.tag = index_tag;

希望它可以帮助任何和我有同样问题的人:)

于 2012-07-30T07:04:25.203 回答