日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

8.花名册

發布時間:2023/12/29 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 8.花名册 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

打開花名冊頭文件

  XMPPRoster.h

  XMPPRosterCoreDataStorage.h?  核心數據存儲

?

在appDelegate.h中定義XMPPRoster全局訪問的花名冊屬性模塊

在appDelegate.m中定義XMPPRosterCoreDataStorage數據存儲模塊

  在設置XMPPStream中電子名片模塊下實列化花名冊并激活

  2.3 _xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];

    _xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:_xmppRosterStorage];

    

  3.重新連接模塊添加到XMPPStream

  [_xmppRoster activate:_xmppStream];

  4.添加代理

  [_xmppRoster addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)];

  //銷毀XMPPStream并注銷

  {

  1.刪除代理

  [_xmppRoster removeDelegate:self];

  2.取消激活

  [_xmppRoster deactivate];

  4.內存清理

  _xmppRoster = nil;

  _xmppRosterStorage = nil;

  }

?

?

  創建一個類,RosterViewController繼承UITableViewController 將花名冊的class指向這個類  指定可重用標識符將identifier: RosterCell 

  使用XMPP花名冊存儲需要導入一個CoreData.framework框架

          使用NSFetchedResultsController抓取結果控制器

  在.m文件中導入<CoreData/CoreData.h>頭文件

  并定義一個成員變量NSFetchedResultsController *_fetchedResultsController;

// 表格分組數量?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

{

? ?return _fetchedResultsController.sections.cont;  //返回查詢結果的數量

}

//對應分組中表格的行數

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

  NSArray *sectionData = [_fetchedResultsController sections];

  if(sectionData.count>0){

  id <NSFetchedResultsSectionInfo>sectionInfo = sectionData[section];

  return [sectionInfo numberOfObjects];

  }

  return 0;

}

//表格行內容

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

  static NSString *ID = @"RosterCell";  //ID為表格可重用標識符

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];

  return cell;

  //設置單元格

?

}

?

// 實例化NSFetchedResultsController

導入代理頭文件 設置appDelegate代理方法

-(AppDelegate *)appDelegate{

return [[UIApplication sharedApplication] delegate];

-(void)setupFetchedController{

  0. 如果要針對coreData做數據訪問,都離不開NSManagedObjectContext

  1.實例化NSManagedObjectContext

  ?  NSManagedObjectContext *context = [[[self appDelegate] xmppRosterStorage]mainThreadManagedObjectContext];

  2.實例化NSFetchRequest

  NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"XMPPUserCoreDataStorageObject"];

  3.0實例化一個排序

  NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"displayName" ascending:YES];

  NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"jidStr" ascending:YES];

?  [request setSortDescriptors:@[sort1,sort2]];

  3.實例化NSFetchedResultsController  

     _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request  managedObjectContext:context  sectionNameKeyPath:@"sectionNum"  cacheName:nil];

  //設置FetchedResultsController的代理

  [_fetchedResultsController setDelegate:self];

  4.查詢數據

  NSError *error = nil;

    if (![_fetchedResultsController performFetch:&error]){

  NSLog(@"%@",error.localizedDescription);

  };

}

?//然后再到  設置單元格?

  XMPPUserCoreDataStorageObject *user = [_fetchedResultsController objectAtIndexPath:indexPath];

?  cell.textLabel.text = user.displayName;

?

?

?

?

?

  

  

?

轉載于:https://www.cnblogs.com/qq907374866/p/4275117.html

總結

以上是生活随笔為你收集整理的8.花名册的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。