小编Jac*_*ins的帖子

苦苦挣扎,传递多个参数来执行SelectorInBackground方法

我从早期的Stack Overflow问题中找到了这段代码,该问题描述了如何将多个参数传递给performSelectorInBackground方法.

但是我很难将代码应用到我的问题中,这是我的代码:

- (void)callingMethod {
    NSDictionary * args = [NSDictionary dictionaryWithObjectsAndKeys:
                           cell, @"cell",
                           storyIndex, @"storyIndex",
                           nil];
    [self performSelectorInBackground:@selector(setCellImageWrapper:)
                           withObject:args];
}

- (void)setCellImageWrapper:(NSDictionary *)args {
    [self setCellImage:[[args objectForKey:@"cell"]]
             withIndex:[[args objectForKey:@"storyIndex"] intValue]];
}

- (void) setCellImage: (EventTableCell *)cell withIndex:(int)storyIndex {

    //My Code

}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在尝试将类型为EventTableCell的对象从setCellImageWrapper方法传递给setCellImage方法.当我尝试调用setCellImage -withIndex方法时,我收到错误"Expected Identifier".谁能告诉我我做错了什么?

谢谢,

插口

iphone parameters objective-c selector

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

objective-c:无法将图像写入文档目录

我正在使用这段代码尝试将图像保存到文档目录:

//FOR TESTING ON SIMULATOR 
UIImage* image = [UIImage imageNamed:@"ReceiptImage1.jpg"];
NSData *imageData = UIImagePNGRepresentation(image);
NSString* imageName = @"Receipt1Image1.png";
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];        
[imageData writeToFile:fullPathToFile atomically:NO];

self.receiptImage1 = fullPathToFile;

self.receiptImageView1.image = [UIImage imageWithContentsOfFile:fullPathToFile];

NSLog(@"fullPathToFile %@", fullPathToFile);
Run Code Online (Sandbox Code Playgroud)

但是,这段代码没有将imageViews图像设置为我正在尝试写入文档目录的收据图像.

有人可以解释我做错了什么以及如何解决它?

谢谢,

插口

iphone objective-c uiimageview ios nsdocumentdirectory

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

目标C - 使用可访问性在下载期间不断检查网络连接

我正在使用这段代码检查我的应用程序中的网络连接,如果存在连接,则拉取数据并显示它:

 if([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == NotReachable) {
            errorView = [[UIAlertView alloc] 
                         initWithTitle: @"Network Error" 
                         message: @"No Network connection availible!" 
                         delegate: self 
                         cancelButtonTitle: @"OK" otherButtonTitles: nil]; 
            [errorView show];
        }
        else
        {
            HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
            [self.navigationController.view addSubview:HUD];

            HUD.delegate = self;
            HUD.labelText = @"Performing Initial Download";
            HUD.minSize = CGSizeMake(135.f, 135.f);

            [HUD showWhileExecuting:@selector(pullAndDisplayData) onTarget:self withObject:nil animated:YES];
        }
Run Code Online (Sandbox Code Playgroud)

但是,我想调整此代码,以便在整个下载过程中不断检查互联网连接,如果我失去连接,则停止下载并向用户显示相应的警报消息.任何人都可以建议我如何解决这个问题?

谢谢,

Tysin

iphone objective-c reachability ios

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

CRM 2011 Online - 插件中的无限循环错误 - 无法找到它

我正在使用以下插件,该插件在更新机会时执行:

public class PreOpportunityWin : Plugin
{
    public PreOpportunityWin() : base(typeof(PreOpportunityWin))
    {
        base.RegisteredEvents.Add(
        new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "opportunity", new Action<LocalPluginContext>(ExecuteAutonumber)));
    }

    protected void ExecuteAutonumber(LocalPluginContext localContext)
    {
        Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)localContext.PluginExecutionContext;
        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            //Organization Service
            IOrganizationService service = localContext.OrganizationService;
            //Tracing Service
            ITracingService trace = (ITracingService)localContext.TracingService;

            Entity Target = (Entity)context.InputParameters["Target"];
            var entity = service.Retrieve(
            Target.LogicalName, Target.Id, new ColumnSet(true));
            var entityStatusCode = (OptionSetValue)entity.Attributes["statuscode"];
            if (entityStatusCode.Value == 3)
            {
                //Code to execute if opportunity won
                trace.Trace("In the …
Run Code Online (Sandbox Code Playgroud)

c# plugins dynamics-crm-2011

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

NSAutoreleasepool泄漏 - 不明白为什么?

我有这个代码:

NSNumber *num;
NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];

for (int i=0; i<images_count; i++) {
    num = [NSNumber numberWithInt:images_count];
    [self performSelectorInBackground:@selector(loadData:) withObject:num];
}

[apool release];
[num release];
Run Code Online (Sandbox Code Playgroud)

它会生成以下错误:

2011-06-17 03:10:3​​0.768 CHARLIE [2456:6c03] * __NSAutoreleaseNoPool():类__NSArrayI的对象0x703d0f0自动释放,没有池到位 - 只是泄漏

我不明白为什么泄漏,请有人请解释如何解决这个问题?

非常感谢,

插口

iphone multithreading objective-c nsautoreleasepool ios

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

Facebook登录对话框不适用于UIAlertView,但适用于UIButton

我有这段代码用于显示登录对话框/发布到用户墙:

_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
    self.loginDialog = nil;
    loginDialog = [[FBLoginDialog alloc] init]; 
    [_loginDialog show];
}
// If we have a session and a name, post to the wall!
else if (_facebookName != nil) {
    [self postToWall];
}
// Otherwise, we don't have a name yet, just wait for that to come through.
Run Code Online (Sandbox Code Playgroud)

如果我将此代码连接到按钮,它可以工作.但是,当我将它放在以下方法中时:

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons …
Run Code Online (Sandbox Code Playgroud)

facebook objective-c uialertview ios

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

Objective-C每天在给定时间执行方法 - 杂乱的实现

我有以下(可见)方法不断检查当前时间,并且当达到特定时间(在这种情况下是午夜)时,NSLog语句运行一次以表示正在执行的有用的事情:

- (void) checkTime {

while (true){

    NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];

    NSDate *now = [[NSDate alloc] init];

    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setDateFormat:@"HH:mm"];

    NSString *nowDateString = [outputFormatter stringFromDate:now];

    if([nowDateString isEqualToString:@"00:00"]){
        NSLog(@"Store previous days data..");
        BOOL stillMidnight = YES;
        while(stillMidnight == YES){
            NSDate *latestNow = [[NSDate alloc] init];

            NSDateFormatter *latestOutputFormatter = [[NSDateFormatter alloc] init];
            [latestOutputFormatter setDateFormat:@"HH:mm"];

            NSString *latestString = [latestOutputFormatter stringFromDate:latestNow];
            //Check if it is still midnight
            if([latestString isEqualToString:@"00:01"]){
                //leave while
                stillMidnight = NO;
            }
        }
        NSLog(@"No …
Run Code Online (Sandbox Code Playgroud)

iphone multithreading timer objective-c while-loop

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

UIPIckerView显示图像和字符串

我有一个带有3个组件的UIPickerView,我需要前两个组件来显示一个字符串,第三个组件显示一个图像.我可以通过实施两者来实现这一点:

- (NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
          forComponent:(NSInteger)component reusingView:(UIView *)view
Run Code Online (Sandbox Code Playgroud)

或者我是否需要创建标签并仅实施viewForRow

iphone objective-c uipickerview ios

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

将CSV文件附加到电子邮件目标 - C的问题

我正在使用以下IBAction将包含一些简单收据数据的CSV文件附加到电子邮件中,但是当电子邮件编辑器视图打开时,正文部分中会显示一个灰色文件,当我实际发送邮件时消息发送时根本没有附件.

继承我的代码:

    - (IBAction)actionEmailComposer {
    NSLog(@"Receipts Count: %d", [receipts count]);
    //Create CSV File
    NSMutableString *csvString = [[NSMutableString alloc] init];
    [csvString appendString:@"Date,Business,Category,Paid By,Note, Number,Currency, Amount"];

    for (int i = 0; i < [receipts count]; i++){

        [csvString appendString: [[receipts objectAtIndex:i] receiptDate]];
        [csvString appendString: [[receipts objectAtIndex:i] business]];
        [csvString appendString: [[receipts objectAtIndex:i] category]];
        [csvString appendString: [[receipts objectAtIndex:i] paidBy]];
        [csvString appendString: [[receipts objectAtIndex:i] note]];
        [csvString appendString: [[receipts objectAtIndex:i] number]];
        [csvString appendString: [[receipts objectAtIndex:i] currency]];
        [csvString appendString: [[receipts objectAtIndex:i] amount]];

    }

    [csvString writeToFile:@"test.csv" atomically:YES encoding:NSUTF8StringEncoding error:NULL]; …
Run Code Online (Sandbox Code Playgroud)

csv iphone objective-c ios mfmailcomposeviewcontroller

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

将自定义实体从一个解决方案导入另一个解决方案

我在我的一个解决方案中有一个自定义实体,我需要另一个.如何将实体从一个解决方案导入另一个解决方案?

dynamics-crm dynamics-crm-2011

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