小编use*_*666的帖子

UITableView延迟加载优化

我有UITableView.在tableView:cellForRow:atIndexPath:方法中(当数据填充到单元格时)我实现了某种延迟加载.如果在后台rowData NSDictionary程序启动requestDataForRow:方法中没有键(键==行号)的对象.因此,在单元格变为可见之后,单元格中的数据会被填充一点.这是代码:

static int requestCounter=0;

-(void)requestDataForRow:(NSNumber *)rowIndex
{
    requestCounter++;
    //NSLog(@"requestDataForRow: %i", [rowIndex intValue]);
    PipeListHeavyCellData *cellData=[Database pipeListHeavyCellDataWithJobID:self.jobID andDatabaseIndex:rowIndex];
    [rowData setObject:cellData forKey:[NSString stringWithFormat:@"%i", [rowIndex intValue]]];
    requestCounter--;

    NSLog(@"cellData.number: %@", cellData.number);

    if (requestCounter==0)
    {
        //NSLog(@"reloading pipe table view...");
        [self.pipeTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    };
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"pipeCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    [[NSBundle mainBundle] loadNibNamed:@"PipesForJobCell" owner:self options:nil];
    cell = pipeCell;
    self.pipeCell = nil;


    PipeListHeavyCellData *cellData=[[PipeListHeavyCellData alloc] init]; …
Run Code Online (Sandbox Code Playgroud)

iphone lazy-loading objective-c uitableview ipad

6
推荐指数
1
解决办法
4011
查看次数

用静态方法在UIView(切孔)上绘制清晰的颜色

我有一个iPhone应用程序,我需要实现以下方法:

+(UITextView *)textView:(UITextView *) withCuttedRect:(CGRect)r
Run Code Online (Sandbox Code Playgroud)

此方法必须从中删除(填充[UIColor clearColor])rect 并返回对象.rUITextViewUITextView

用户将从UITextView切割孔看到后面的视图.

怎么做到呢?

iphone core-graphics objective-c uiview ios

6
推荐指数
1
解决办法
4920
查看次数

Facebook sdk发布在iPhone应用程序的墙上

我在iPhone应用程序中在墙上实现Facebook发布时遇到问题.我安装SDK和链接框架登录工作正常.这是代码:

-(IBAction)loginButtonPressed:(id)sender
{
    NSLog(@"loginButtonPressed: called");

    AppDelegate *appdel=[[UIApplication sharedApplication] delegate];
    appdel.facebookSession=[[FBSession alloc] init];
    [appdel.facebookSession openWithCompletionHandler:^(FBSession *session, 
                                                     FBSessionState status, 
                                                     NSError *error)
    {
        //
    }];
}
Run Code Online (Sandbox Code Playgroud)

但是我在用户的墙上发布消息时遇到了问题.这是代码:

-(IBAction)likeButtonPressed:(id)sender
{
    NSLog(@"likeButtonPressed: called");
    // Post a status update to the user's feedm via the Graph API, and display an alert view 
    // with the results or an error.

    NSString *message = @"test message";
    NSDictionary *params = [NSDictionary dictionaryWithObject:message forKey:@"message"];

    // use the "startWith" helper static on FBRequest to both create and start a request, with …
Run Code Online (Sandbox Code Playgroud)

iphone facebook objective-c ios

6
推荐指数
1
解决办法
2万
查看次数

将图像转换为base64并以JSON格式上传到服务器

我有个问题.我需要将base64字符串转换为JSON字符串并将其传递给服务器.例如,我有一个base64字符串/9j/4AAQSkZJRgABAQAAAQABAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACqADAAQAAAABAAAACgAAAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/Z

我需要将其转换为JSON格式.我做以下事情:

+(NSData *)prepareForUploading:(NSString *)base64Str
{
    NSDictionary *dict=[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:base64str, nil] forKeys:[NSArray arrayWithObjects:@"picture", nil]];

    NSData *preparedData=[NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];    
    return preparedData;
};
Run Code Online (Sandbox Code Playgroud)

在这我是如何制作的 NSURLRequest

-(NSString *)uploadPict:(NSString *)pict
{
    NSLog(@"Server: upload: called");
    NSData *prepPictData=[[self class] prepareForUploading:pict];
    NSString *preparedBase64StrInJSON=[[NSString alloc] initWithData:prepPictData encoding:NSUTF8StringEncoding];

    //here I'm adding access token to request
    NSString *post = [NSString stringWithFormat:@"accessToken=%@&object=%@", self.key, preparedBase64StrInJSON];
    NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@upload.aspx", serverAPIPath]]];
    [request …
Run Code Online (Sandbox Code Playgroud)

iphone base64 objective-c nsurlrequest ipad

1
推荐指数
1
解决办法
2339
查看次数

在按UIViewController时隐藏UITabBarController的标签栏

我有一个标签栏应用程序.这是启动代码

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];



    self.tabBarController=[[UITabBarController alloc] init];


    StartViewController *startViewController=[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
    NavRootViewController *navRootViewController=[[NavRootViewController alloc] initWithNavControllerWithSubViewController:startViewController];

    HelpViewController *helpViewController=[[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];

    SettingsViewController *settingsViewController=[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];

    AboutUsViewController *aboutUsViewController=[[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];

    [self.tabBarController setViewControllers:[NSArray arrayWithObjects: navRootViewController, helpViewController, settingsViewController, aboutUsViewController, nil]];



    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController=self.tabBarController;
Run Code Online (Sandbox Code Playgroud)

使用4个标签栏选项卡启动应用程序 用户在第一个选项卡的导航控制器的根视图控制器中按下开始按钮后调用此操作

-(IBAction)startPressed:(id)sender
{
    NSLog(@"startPressed: called");


    RootViewController *vController=[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    [self.navigationController pushViewController:vController animated:YES];

}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我需要隐藏标签栏我的RootViewController 财产hidesBottomBarWhenPushed …

iphone objective-c uitabbarcontroller uitabbar ios

0
推荐指数
1
解决办法
4528
查看次数