解决方案 »

  1.   

    UITableView的datasource是一定是要实现numberOfRowsInSection:这个方法的吧?除非不设置datasource,否则一定要实现numberOfRowsInSection:这个方法。
      

  2.   

    设置了datasource和delegate。。现在的问题是,我把跟UITableView相关的所有代码全部删除了,编译还是这个错误
      

  3.   


    //
    //  ClientManager.m
    //  adSDK
    //
    //  Created by ww on 14-7-18.
    //  Copyright (c) 2014年 lhyhzjc. All rights reserved.
    //#import "ClientManager.h"
    #import <MapKit/MapKit.h>#define SWITCH_TIME 5@implementation ClientManager-(id)init
    {
        self = [super init];
        [self getSystemInfo];
        [self getMapInfo];
        [self getUserKey]; // 1
        [self getCarrierInfoAndConnectType]; //2
        [self getPhoneType];
        [self initBanner];
        return self;
    }-(void)initBanner
    {
        self.mMainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
        self.mMainView.clipsToBounds = YES;
        self.mBannerArray = [[NSMutableArray alloc] init];
        self.mCurrentIndex = -1;
        self.mClickId = @"0";
    }-(void)showPopBannerInView:(UIView *)mainView atPos:(CGPoint)pos withRect:(CGRect)rect
    {
        NSArray* array = [[NSUserDefaults standardUserDefaults] objectForKey:@"adinfo"];
        
        UIView* view = [[UIView alloc] initWithFrame:rect];
        view.center = pos;
        
        UIView* topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, 50)];
        topView.backgroundColor = [UIColor colorWithRed:253.0f/255 green:93.0f/255 blue:58.0f/255 alpha:1.0];
        [view addSubview:topView];
        
        
        UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 20)];
        label.center = CGPointMake(0.5*topView.frame.size.width, 0.5*topView.frame.size.height);
        label.text = @"精品推荐";
    }
    -(void)showBannerInView:(UIView*)mainView atPos:(CGPoint)pos
    {
        
        NSArray* array = [[NSUserDefaults standardUserDefaults] objectForKey:@"adinfo"];
        
        for (int i=0; i<[array count]; i++) {
            NSMutableString* localpath = [NSMutableString stringWithString:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
            NSString* addpath = [NSString stringWithFormat:@"/%@.png",array[i][@"id"]];
            [localpath appendString:addpath];
        
            UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:localpath]];
            imgView.frame = CGRectMake(0, 0, 320, 50);
            
            UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50.0)];
            
            [view addSubview:imgView];
            view.transform = CGAffineTransformMakeScale(1,1);        view.frame = CGRectOffset(view.frame,320+i*320, 0);
            [mMainView addSubview:view];
            
            NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys: array[i][@"id"],@"id",array[i][@"url"],@"url",view,@"view", nil];
            mBannerArray[i] = dic;
        }
        
        
        UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0,0, 320, 50.0)];
        [button setBackgroundColor:[UIColor clearColor]];
        [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 5175;
        [mMainView addSubview:button];
        [mMainView bringSubviewToFront:button];
        
        
        mMainView.center = CGPointMake(160, 455);
        [mainView addSubview:self.mMainView];
        
        [NSTimer scheduledTimerWithTimeInterval:SWITCH_TIME target:self selector:@selector(animationBanner:) userInfo:nil repeats:YES];
    }-(UIButton*)getClientButton
    {
        return (UIButton*)[mMainView viewWithTag:5175];
    }-(void)click
    {
        if (mCurrentIndex==-1 || [mBannerArray count]<=0 )
        {
            return;
        }
        if (![self netWorking])
        {
            return ;
        }
        self.mClickId = mBannerArray[mCurrentIndex][@"id"];
        
        block();
        
        NSString* path = [NSString stringWithFormat:@"http://%@",mBannerArray[mCurrentIndex][@"url"]];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:path ]];
    }
    -(NSString*)clickAdId
    {
        return  self.mClickId;
    }-(void)setClickAdId:(NSString *)Id
    {
        self.mClickId = Id;
    }-(void)animationBanner:(id)sender
    {
        [self sortViews];
        
        if ([mBannerArray count]==0 || ([mBannerArray count]==1 && mCurrentIndex!=-1))
        {
            return ;
        }
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationBeginsFromCurrentState:NO];
        
        for (int i=0; i<[mBannerArray count]; i++) {
            UIView* view = mBannerArray[i][@"view"];
            view.frame = CGRectOffset(view.frame, -320, 0);
        }
        
        [UIView commitAnimations];
        
        mCurrentIndex++;
        if (mCurrentIndex>=[mBannerArray count]) {
            mCurrentIndex=0;
        }}-(void)sortViews
    {
        if([mBannerArray count]>1)
        {
            for (int i=0; i<[mBannerArray count]; i++) {
                UIView* view = mBannerArray[i][@"view"];
                if(view.frame.origin.x <-150)
                {
                    view.frame = CGRectOffset(view.frame, 320*[mBannerArray count], 0);
                    break;
                }
            }
        }
    }
    -(void)addBanner:(NSDictionary*)ad
    {
        [self sortViews];
        
        if(mCurrentIndex == -1)
        {
            mCurrentIndex = 0;
        }
        
        NSMutableString* localpath = [NSMutableString stringWithString:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
        NSString* addpath = [NSString stringWithFormat:@"/%@.png",ad[@"id"]];
        [localpath appendString:addpath];
        
        UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:localpath]];
        imgView.frame = CGRectMake(0, 0, 320, 50);
        UIView* view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50.0)];
        [view addSubview:imgView];
        view.transform = CGAffineTransformMakeScale(1,1);
        [mMainView addSubview:view];
        view.frame = CGRectOffset(view.frame, 320*([mBannerArray count]-mCurrentIndex), 0);
        NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys: ad[@"id"],@"id",ad[@"url"],@"url",view,@"view", nil];
        [mBannerArray addObject:dic];
        
        for (int i=0; i<mCurrentIndex; i++) ////清楚数据后 mCurrentIndex还未能清楚为0
        {
            UIView* view = mBannerArray[i][@"view"];
            if (view.frame.origin.x<0) {
                continue;
            }
            view.frame = CGRectOffset(view.frame, 320, 0);
        }
        
        UIButton* button = [self getClientButton];
        [mMainView bringSubviewToFront:button];
        
        for (int i=0; i<[mBannerArray count]; i++) {
            UIView* view = mBannerArray[i][@"view"];
            NSLog(@"mCur = %ld  id为%@的偏移为%f",mCurrentIndex,mBannerArray[i][@"id"], view.frame.origin.x );
        }
    }-(void)deleleBanner:(NSInteger)index
    {
        [self sortViews];
        
        unsigned long int count = [mBannerArray count];
        
        UIView* banner = mBannerArray[index][@"view"];
        [banner removeFromSuperview];
        [mBannerArray removeObjectAtIndex:index];
        
        if(index<mCurrentIndex)
        {
            for (unsigned long int i=index; i<mCurrentIndex-index-1; i++) {
                UIView* view = mBannerArray[i][@"view"];
                if (view.frame.origin.x<0) {
                    continue;
                }
                view.frame = CGRectOffset(view.frame, -320, 0); //左移
            }
            mCurrentIndex--;
        }
        else if(index>=mCurrentIndex)
        {
            for (int i=0; i<mCurrentIndex; i++) {
                UIView* view = mBannerArray[i][@"view"];
                if (view.frame.origin.x<0) {
                    continue;
                }
                view.frame = CGRectOffset(view.frame, -320, 0); //左移
            }
            for (unsigned long int i=index; i<count-1; i++) {
                UIView* view = mBannerArray[i][@"view"];
                if (view.frame.origin.x<0) {
                    continue;
                }
                view.frame = CGRectOffset(view.frame, -320, 0); //左移
            }
            if (mCurrentIndex==index && mCurrentIndex==count-1) {
                mCurrentIndex=0;
            }
        }
    }-(void)update
    {
        NSArray* array = [[NSUserDefaults standardUserDefaults] objectForKey:@"adinfo"];
        for (int i=0; i<[array count]; i++)
        {
            BOOL flag = NO;
            for (int j=0; j<[mBannerArray count]; j++)
            {
                if ([array[i][@"id"] isEqualToString: mBannerArray[j][@"id"]])
                {
                    flag = YES;
                }
            }
            if (!flag)
            {
                [self addBanner:array[i]];
                NSLog(@"客户端更新后增加的广告id为:%@",array[i][@"id"]);
            }
        }
        
        for (int i=[mBannerArray count]-1; i>=0; i--)
        {
            BOOL flag = NO;
            for (int j=0; j<[array count]; j++)
            {
                if ([mBannerArray[i][@"id"] isEqualToString: array[j][@"id"]])
                {
                    flag = YES;
                }
            }
            if (!flag)
            {
                NSLog(@"客户端更新后删除的广告id为:%@",mBannerArray[i][@"id"]);
                [self deleleBanner:i];
            }
        }
    }
    -(void) getSystemInfo
    {
        if([[UIDevice currentDevice].systemVersion floatValue] < 7.0)
        {
            mIsIOS7 = NO;
        }
        else
        {
            mIsIOS7 = YES;
        }
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        mScreenHeight = screenRect.size.height;
    }
    - (void) getMapInfo
    {
        self.map=[[MKMapView alloc] init];
        self.map.delegate = (id)self;
        self.map.hidden = YES;
        self.map.showsUserLocation = YES;
    }
    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
    {
        CLLocation * newLocation = userLocation.location;
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
            CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];
            CLGeocodeCompletionHandler handle = ^(NSArray *places,NSError *error)
            {
                for (CLPlace * placeMark in places)
                {
                    self.map.showsUserLocation = NO;
                    self.mUserPos = [placeMark.administrativeArea stringByReplacingOccurrencesOfString:@"市" withString:@""];
                    NSLog(@"地址:%@,",self.mUserPos);
                }
            };
            [clGeoCoder reverseGeocodeLocation:newLocation completionHandler:handle];
        }
    }-(BOOL)netWorking
    {
        return YES;
    }
    @end
      

  4.   

    这里面并没有用到TableView,确定是这个类里面的问题吗?
      

  5.   

    那是因为我删除了和TableView有关的代码啊,也删除好多无关代码。
    每次都是到 laber.text = @"精品推荐"; 这一行就跳出那个函数了,
    这一行的下面一句是 label.backgroundColor = [UIColor clearColor];