Добавьте IBAction к кнопке в пользовательском UItableviewCell - PullRequest
0 голосов
/ 02 февраля 2012

Поэтому я хочу сделать заказ на разные товары. В этом У меня есть пользовательская ячейка uitableview с кнопкой на ней. В дать NSMutualArray с моим IBAction. Это мой IBAction. Я выделил свой массивBestelling в моей viewdidload.

-(IBAction)addProduct:(NSMutableArray *) arrProduct{
    [arrayBestelling addObject:arrProduct];

}

Хорошо, это весь мой метод просмотра таблицы.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    productTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"productTableviewCell" owner:nil options:nil];

        for (UIView *view in views) {
            if([view isKindOfClass:[UITableViewCell class]])
            {   
                cell = (productTableviewCell*)view;
            }
            }
    }
    if(searching) {
        cell.proId.text = [[[copyArrayProducts valueForKey:@"Pro_id"] objectAtIndex:indexPath.row] objectAtIndex:0];
        cell.product.text = [[[copyArrayProducts valueForKey:@"Pro_naam"] objectAtIndex:indexPath.row] objectAtIndex:0];
        cell.prijs.text = [[[copyArrayProducts valueForKey:@"Pro_prijs"] objectAtIndex:indexPath.row] objectAtIndex:0];

    }else {


    NSString *strId = [[[arrayProducts valueForKey:@"Pro_id"] objectAtIndex:indexPath.row] objectAtIndex:0];
    NSString *strNaam = [[[arrayProducts valueForKey:@"Pro_naam"] objectAtIndex:indexPath.row] objectAtIndex:0];
    cell.product.text = strNaam;
    cell.proId.text = strId;
    NSMutableString *strPrijs = [NSMutableString stringWithString: @"€ "];
    [strPrijs appendString:[[[arrayProducts valueForKey:@"Pro_prijs"] objectAtIndex:indexPath.row] objectAtIndex:0]];
    cell.prijs.text = strPrijs;
    NSString *strAantal = cell.aantal.text;

    arrayProBestelling = [[NSMutableArray alloc] init];
        [arrayProBestelling addObject:strId];
        [arrayProBestelling addObject:strNaam];
        [arrayProBestelling addObject:strPrijs];
        [arrayProBestelling addObject:strAantal];

    }

   **[cell.btnadd addTarget:self action:@selector(addProduct:arrayProBestelling) forControlEvents:UIControlEventTouchUpInside]**

    return cell;

}

Кто-нибудь может помочь?

РЕДАКТИРОВАТЬ!

Ответы [ 2 ]

0 голосов
/ 02 февраля 2012

Вы можете добавить кнопки в -accessoryView для ячейки.Если вы создаете свою собственную ячейку, это совсем не сложно.Но для простой простой реализации просто создайте UIButton, назначьте цель и добавьте ее в accessoryView.

0 голосов
/ 02 февраля 2012

Я рекомендую добавить пользовательский класс данных с именем Product с такими именами, ценами и т. Д. В качестве полей. Затем вы добавляете товары в MutableArray.

-(IBAction)addProduct:(Product *) product{
    [productArray addObject:product];
}

Затем вы можете отсортировать массив, используя SortDescriptors: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/SortDescriptors/Concepts/Creating.html

...