腾讯分享sdk的一个自定义cell方法

看QQ分享,发现一个不错的自定义cell方法,如下:
xiaolongzhang 张小龙?😳

//
//  cellInfo.h
//  sdkDemo
//
//  Created by  <mark>xiaolongzhang</mark>  on 13-7-3.
//  Copyright (c) 2013年 xiaolongzhang. All rights reserved.
//
#import <Foundation/Foundation.h>

typedef enum
{
    kApiQZone,
    kApiQQVip,
    kApiQQT,
    kApiQQ,
    kApiQuick,
}apiType;

@interface cellInfo : NSObject
+ (cellInfo *)info:(NSString *)title target:(id)target Sel:(SEL)sel viewController:(UIViewController *)viewController userInfo:(id)userInfo;
+ (cellInfo *)info:(NSString *)title target:(id)target Sel:(SEL)sel viewController:(UIViewController *)viewController;

@property (nonatomic, retain)NSString *title;
@property (nonatomic, assign)id  target;
@property (nonatomic, assign)SEL sel;
@property (nonatomic, retain)UIViewController *viewController;
@property (nonatomic, retain)id userInfo;
@end

//
//  cellInfo.m
//  sdkDemo
//
//  Created by xiaolongzhang on 13-7-3.
//  Copyright (c) 2013年 xiaolongzhang. All rights reserved.
//
#import "cellInfo.h"

@implementation cellInfo

+ (cellInfo *)info:(NSString *)title target:(id)target Sel:(SEL)sel viewController:(id)viewController
{
    cellInfo *info = [[cellInfo alloc] init];
    info.title = title;
    info.target = target;
    info.sel = sel;
    info.viewController = viewController;
    info.userInfo = nil;
    return info;
}

+ (cellInfo *)info:(NSString *)title target:(id)target Sel:(SEL)sel viewController:(UIViewController *)viewController userInfo:(NSDictionary *)userInfo
{
    cellInfo *info = [[cellInfo alloc] init];
    info.title = title;
    info.target = target;
    info.sel = sel;
    info.viewController = viewController;
    info.userInfo = userInfo;
    return info;
}

@synthesize title = _title;
@synthesize target = _target;
@synthesize sel = _sel;
@synthesize viewController = _viewController;
@synthesize userInfo = _userInfo;
@end
@interface sdkDemoViewController ()
{
    FGalleryViewController  *_localGallery;
    NSInteger               _currentTableViewTag;
}

@property (nonatomic, retain)NSMutableArray *sectionName;
@property (nonatomic, retain)NSMutableArray *sectionRow;

@end

@implementation sdkDemoViewController

@synthesize sectionName = _sectionName;
@synthesize sectionRow = _sectionRow;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self)
    {
        // Custom initialization
        self.sectionName = [NSMutableArray arrayWithCapacity:1];
        self.sectionRow = [NSMutableArray arrayWithCapacity:1];
        [self loadData];
        _isLogined = NO;
        _currentTableViewTag = 0;
    }

    return self;
}

- (void)loadData
{
    NSMutableArray *cellLogin = [NSMutableArray arrayWithCapacity:1];
    [cellLogin addObject:[cellInfo info:@"第三方登录" target:self Sel:@selector(login) viewController:nil]];
    [[self sectionName] addObject:@"登录"];
    [[self sectionRow] addObject:cellLogin];
    
    NSMutableArray *cellApiInfo = [NSMutableArray arrayWithCapacity:4];
    
    [cellApiInfo addObject:[cellInfo info:@"QQ定向分享" target:nil Sel:@selector(pushSelectViewController:) viewController:nil userInfo:[NSNumber numberWithInteger:kApiQQ]]];
    [cellApiInfo addObject:[cellInfo info:@"QQ空间" target:self Sel:@selector(pushSelectViewController:) viewController:nil userInfo:[NSNumber numberWithInteger:kApiQZone]]];
    [cellApiInfo addObject:[cellInfo info:@"QQ会员" target:nil Sel:@selector(pushSelectViewController:) viewController:nil userInfo:[NSNumber numberWithInteger:kApiQQVip]]];
    
    [[self sectionName] addObject:@"api"];
    [[self sectionRow] addObject:cellApiInfo];
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)login
{
    NSArray* permissions = [NSArray arrayWithObjects:
                     kOPEN_PERMISSION_GET_USER_INFO,
                     kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,
                     kOPEN_PERMISSION_ADD_ALBUM,
                     kOPEN_PERMISSION_ADD_ONE_BLOG,
                     kOPEN_PERMISSION_ADD_SHARE,
                     kOPEN_PERMISSION_ADD_TOPIC,
                     kOPEN_PERMISSION_CHECK_PAGE_FANS,
                     kOPEN_PERMISSION_GET_INFO,
                     kOPEN_PERMISSION_GET_OTHER_INFO,
                     kOPEN_PERMISSION_LIST_ALBUM,
                     kOPEN_PERMISSION_UPLOAD_PIC,
                     kOPEN_PERMISSION_GET_VIP_INFO,
                     kOPEN_PERMISSION_GET_VIP_RICH_INFO,
                     nil];
    
    [[[sdkCall getinstance] oauth] authorize:permissions inSafari:NO];
}

- (void)pushSelectViewController:(NSNumber *)apiType
{
    UIViewController *rootViewController = nil;
    switch ([apiType unsignedIntegerValue]) {
        case kApiQZone:
            rootViewController = [[QZoneTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
            break;
        case kApiQQVip:
            rootViewController = [[QQVipTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
            break;
        case kApiQQ:
            rootViewController = [[QQApiDemoController alloc] init];
            break;
        default:
            break;
    }
    [[self navigationController] pushViewController:rootViewController animated:YES];
    __RELEASE(rootViewController);
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return [[self sectionName] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.

    return [[[self sectionRow] objectAtIndex:section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    NSUInteger section = [indexPath section];
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:CellIdentifier];
    }
    
    NSString *title = nil;
    NSMutableArray *array = [[self sectionRow] objectAtIndex:section];
    if ([array isKindOfClass:[NSMutableArray class]])
    {
        title = [[array objectAtIndex:row] title];
    }
    
    if (nil == title)
    {
        title = @"未知";
    }
    
    [[cell textLabel] setText:title];
    [[cell textLabel] setTextAlignment:NSTextAlignmentCenter];
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
//    if (0 == indexPath.row
//        || 1 == indexPath.row)
//    {
//        [[cell textLabel] setEnabled:YES];
//    }
    
    // Configure the cell...
    
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[self sectionName] objectAtIndex:section];
}


#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSInteger row = [indexPath row];
    NSInteger section = [indexPath section];
    
    NSArray *array = [[self sectionRow] objectAtIndex:section];
    if ([array isKindOfClass:[NSMutableArray class]])
    {
        cellInfo *info = (cellInfo *)[array objectAtIndex:row];
        if ([self respondsToSelector:[info sel]])
        {
            if (nil == [info userInfo])
            {
                [self performSelector:[info sel]];
            }
            else
            {
                [self performSelector:[info sel] withObject:[info userInfo]];
            }
        }
    }
    
    [[tableView cellForRowAtIndexPath:indexPath] setHighlighted:NO animated:NO];
}
@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,007评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,459评论 4 61
  • 做好当下的极致,看似最笨往往却是最聪明的!
    所谓荼靡阅读 1,828评论 0 2
  • 这几天在屏山写生,画了几幅速写。画的一般,但是景色不错。墙白瓦黑,路窄楼高。 给妈妈发了几张照片,她说和她小时候火...
    Miss_Shallow阅读 11,114评论 0 4

友情链接更多精彩内容