简体   繁体   中英

collectionView:numberOfItemsInSection: in UITableviewcell (DetailedCell)

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailedCell collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x1090a9370'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101afa795 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010185d991 objc_exception_throw + 43
    2   CoreFoundation                      0x0000000101b8bbad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000101aec09d ___forwarding___ + 973
    4   CoreFoundation                      0x0000000101aebc48 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000100a46156 -[UICollectionViewData _updateItemCounts] + 283
    6   UIKit                               0x0000000100a462d5 -[UICollectionViewData _prepareToLoadData] + 94
    7   UIKit                               0x0000000100a469d1 -[UICollectionViewData validateLayoutInRect:] + 53
    8   UIKit                               0x0000000100a168b3 -[UICollectionView layoutSubviews] + 170
    9   UIKit                               0x000000010051bb27 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
    10  QuartzCore                          0x0000000100120a22 -[CALayer layoutSublayers] + 151
    11  QuartzCore                          0x0000000100115589 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
    12  QuartzCore                          0x0000000100120956 -[CALayer layoutIfNeeded] + 162
    13  UIKit                               0x00000001005bbfc2 -[UIViewController window:setupWithInterfaceOrientation:] + 264
    14  UIKit                               0x00000001004fab4d -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4360
    15  UIKit                               0x00000001004f9a3f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
    16  UIKit                               0x00000001004f998f -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 101
    17  UIKit                               0x00000001004f8c9e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 377
    18  UIKit                               0x00000001005afd4a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 147
    19  UIKit                               0x00000001004f3a87 -[UIWindow addRootViewControllerViewIfPossible] + 506
    20  UIKit                               0x00000001004f3bd5 -[UIWindow _setHidden:forced:] + 275
    21  UIKit                               0x00000001004fcca2 -[UIWindow makeKeyAndVisible] + 51
    22  ZaakitDetailedView                  0x0000000100001eb6 -[AppDelegate application:didFinishLaunchingWithOptions:] + 950
    23  UIKit                               0x00000001004ba95c -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 264
    24  UIKit                               0x00000001004bb014 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1269
    25  UIKit                               0x00000001004bebe8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
    26  UIKit                               0x00000001004cfaab -[UIApplication handleEvent:withNewEvent:] + 3092
    27  UIKit                               0x00000001004cff1e -[UIApplication sendEvent:] + 79
    28  UIKit                               0x00000001004c02be _UIApplicationHandleEvent + 618
    29  GraphicsServices                    0x00000001033f5bb6 _PurpleEventCallback + 762
    30  GraphicsServices                    0x00000001033f567d PurpleEventCallback + 35
    31  CoreFoundation                      0x0000000101a7c819 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    32  CoreFoundation                      0x0000000101a7c5ee __CFRunLoopDoSource1 + 478
    33  CoreFoundation                      0x0000000101aa5ab3 __CFRunLoopRun + 1939
    34  CoreFoundation                      0x0000000101aa4f33 CFRunLoopRunSpecific + 467
    35  UIKit                               0x00000001004be4bd -[UIApplication _run] + 609
    36  UIKit                               0x00000001004c0043 UIApplicationMain + 1010
    37  ZaakitDetailedView                  0x0000000100007d73 main + 115
    38  libdyld.dylib                       0x00000001030a07e1 start + 0
    39  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I am createing three UITableview customcells.Its Calling two section (index.section ==0) and (index.section ==1) but not enter (index.section == 2). And aslo crash the program. This is my Code. Please check onces.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return [imagesArray  count];
        return [self.ResponeDataArray count];
        return [self.ResponeDataArray count];
        return [pricearr count];
        return [pricearr1 count];
         return [SizeArray count];
    }
    else if (section == 1)
    {
        return [AboutProductArr count];
           }
    else if ( section == 3)
    {
       return [sampleData count];
        return [sellerinfoarr count];
        return [sellerLbl count];
        return [sellImage count];
    }

    return 0;

}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    if (indexPath.section == 0)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
        if (cell == nil)
        {
         cell = [[DetailedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
         }

        cellData = [imagesArray objectAtIndex:[indexPath section]];

        imageData = [cellData objectForKey:@"articles"];

        [cell setCollectionData:imageData];



        cell.productTitleObj.text = [self.ResponeDataArray objectAtIndex:indexPath.row];
        cell.mrpObj.text = [pricearr objectAtIndex:indexPath.row];
        cell.offerpriceOb.text = [pricearr1 objectAtIndex:indexPath.row];

        cell.selectQuantity.tag = indexPath.row;
        cell.selectQuantity.delegate =self;
        cell.selectSizeObj.delegate = self;
     return cell;
    }
     if (indexPath.section == 1)
    {
        AboutProductCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];

        // [self setUpCell:cell1 atIndexPath:indexPath];

        cell1.aboutProductObj.text = [AboutProductArr objectAtIndex:indexPath.row];
       return cell1;
    }
    if (indexPath.section == 2)
    {
        SellerInformationCell *cell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier3];
        if (cell2 == nil)
        {
            cell2 = [[SellerInformationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier3];
        }

        cellData1 = [sampleData1 objectAtIndex:[indexPath section]];

        SellerimageArray = [cellData1 objectForKey:@"Images"];

        [cell2 setCollectionData1:SellerimageArray];


        cell2.storeNameObj.text = [sellerinfoarr objectAtIndex:indexPath.row];
        cell2.moreProductNameObj.text = [sellerLbl objectAtIndex:indexPath.row];
        cell2.storeImageObj.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[sellImage objectAtIndex:indexPath.row]]];


        return cell2;
    }

    return nil;
}

setCollectionData is Method its uses in UICollectionview..

Error seems like you are using your DetailedCell as datasource and delegate of collection view.

So, make sure you have set data source and delegate to self from that detailcell class.

You are sending wrong number of item in section to collection view.

Hope this will help :)

Drag and Drop the collection view datasource and delegate on the cell where you are using collection view在此处输入图片说明

你错误地设置了数据源和委托,而不是集合视图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM