iOS開發基礎知識--片段23

來源:互聯網
上載者:User

標籤:

1:關於UITableView中關於行重複載入的問題

  在Cell裡重寫prepareForReuse,對一些控制項進行清空;

比較簡單:-(void)prepareForReuse{    [super prepareForReuse];    _content_label.text = nil;    _time_date_label.text = nil;    _name_label.text = nil;    _career_label.text = nil;}下面這個是我在cell載入一個自定議的視圖BLSPrincipalItemView

-(void)prepareForReuse

{

    [super prepareForReuse];

    self.titleLabel.text = nil;

    for (UIView *view in [self.contentView subviews])

    {

        if ([view isKindOfClass:[BLSPrincipalItemView class]])

        {

            [view removeFromSuperview];

        }

    }

}


注意self.contentView,否則在IOS7會沒有效果,還是重複的增加跟圖片錯亂

這邊有一段對它進行一個詳細的說明:

cell被重用如何提前知道? 重寫cell的prepareForReuse官方標頭檔中有說明.當前已經被分配的cell如果被重用了(通常是滾動出螢幕外了),會調用cell的prepareForReuse通知cell.注意這裡重寫方法的時候,注意一定要調用父類方法[super prepareForReuse] .這個在使用cell作為網路訪問的代理容器時尤其要注意,需要在這裡通知取消掉前一次網路請求.不要再給這個cell發資料了.- (void)prepareForReuse{    [super prepareForReuse];}自訂UITableViewCell的方法有很多 發現一些人都會遇到自己定義的cell裡面圖片錯亂的問題 這個問題往往是因為沒有實現prepareForReuse這個方法導致的.UITableViewCell在向下滾動時複用, 得用的cell就是滑出去的那些, 而滑出去的cell裡顯示的資訊就在這裡出現了 解決的方法就是在UITableViewCell的子類裡實現perpareForReuse方法, 把內容清空掉

 2:查看虛擬器的路徑

    NSString *path = NSHomeDirectory();//主目錄    NSLog(@"NSHomeDirectory:%@",path);

 3:ios8 模擬器路徑

IOS 8.0 之前的路徑如下:/Users/TESTUSER/Library/Application Support/iPhone SimulatoriOS 8.0 後的路徑如下:/Users/TESTUSER/Library/Developer/CoreSimulator/Devices/8978B626-387E-40AF-AE99-6DEE931C5FA4/data/Containers/Data/Application

4:CocoaLumberjack記錄檔產生的位置

/Users/TESTUSER/Library/Developer/CoreSimulator/Devices/8978B626-387E-40AF-AE99-6DEE931C5FA4/data/Containers/Data/Application/7CA2354E-5B3A-47E2-8F69-A59764538FA1/Library/Caches/Logs/

5:webView載入新聞的URL

    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, ScreenWidth, ScreenHeight)];    self.webView.delegate = self;    NSURL *url = [NSURL URLWithString:self.urlStr];    NSURLRequest *request = [NSURLRequest requestWithURL:url];    [self.webView loadRequest:request];       [self.view addSubview:self.webView];

6:多手指多點擊響應

- (void)viewDidLoad {    [super viewDidLoad];        UITapGestureRecognizer *myFingersTwoTaps =    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(FingersTaps)];    [myFingersTwoTaps setNumberOfTapsRequired:4];    [myFingersTwoTaps setNumberOfTouchesRequired:2];    [[self view] addGestureRecognizer:myFingersTwoTaps];}- (void)FingersTaps {    NSLog(@"Action: 兩個手指  連續點擊四下");}

7:添加pch檔案的步聚

1:建立新檔案 ios->other->PCH file,建立一個pch檔案:“工程名-Prefix.pch”:2:將building setting中的precompile header選項的路徑添加“$(SRCROOT)/項目名稱/pch檔案名稱”(例如:$(SRCROOT)/LotteryFive/LotteryFive-Prefix.pch)3:將Precompile Prefix Header為YES,先行編譯後的pch檔案會被緩衝起來,可以提高編譯速度

 8:隱藏狀態列跟導覽列

viewWillAppear表示視圖將呈現出來前-(void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    [self.navigationController.navigationBar setTranslucent:YES];    [self.navigationController setNavigationBarHidden:YES];}

 9:修改表格行預設分隔線存空隙的問題

    if (!_myTableView) {        _myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];        _myTableView.backgroundColor = [UIColor clearColor];        _myTableView.showsVerticalScrollIndicator = NO;        _myTableView.showsHorizontalScrollIndicator=NO;                _myTableView.tableFooterView=[[UIView alloc]init];        _myTableView.dataSource = self;        _myTableView.delegate = self;        [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:BLSMaterialDocumentsViewController_CellIdentifier];        [self.view addSubview:_myTableView];                if ([self.myTableView respondsToSelector:@selector(setLayoutMargins:)]) {            self.myTableView.layoutMargins=UIEdgeInsetsZero;        }        if ([self.myTableView respondsToSelector:@selector(setSeparatorInset:)]) {            self.myTableView.separatorInset=UIEdgeInsetsZero;        }    }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    leftTableCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([leftTableCell class]) forIndexPath:indexPath];    cell.curLeftTagModel = [self.dataList objectAtIndex:indexPath.section];    cell.hasBeenSelected = (cell.curLeftTagModel==self.curSelectModel);            //修改表格行預設分隔線存空隙的問題    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {        cell.layoutMargins=UIEdgeInsetsZero;    }    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {        cell.separatorInset=UIEdgeInsetsZero;    }        return cell;}

iOS開發基礎知識--片段23

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.