我从早期的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".谁能告诉我我做错了什么?
谢谢,
插口
我正在使用这段代码尝试将图像保存到文档目录:
//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图像设置为我正在尝试写入文档目录的收据图像.
有人可以解释我做错了什么以及如何解决它?
谢谢,
插口
我正在使用这段代码检查我的应用程序中的网络连接,如果存在连接,则拉取数据并显示它:
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
我正在使用以下插件,该插件在更新机会时执行:
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) 我有这个代码:
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:30.768 CHARLIE [2456:6c03] * __NSAutoreleaseNoPool():类__NSArrayI的对象0x703d0f0自动释放,没有池到位 - 只是泄漏
我不明白为什么泄漏,请有人请解释如何解决这个问题?
非常感谢,
插口
我有这段代码用于显示登录对话框/发布到用户墙:
_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) 我有以下(可见)方法不断检查当前时间,并且当达到特定时间(在这种情况下是午夜)时,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) 我有一个带有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?
我正在使用以下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) 我在我的一个解决方案中有一个自定义实体,我需要另一个.如何将实体从一个解决方案导入另一个解决方案?
objective-c ×8
iphone ×7
ios ×6
c# ×1
csv ×1
dynamics-crm ×1
facebook ×1
mfmailcomposeviewcontroller ×1
parameters ×1
plugins ×1
reachability ×1
selector ×1
timer ×1
uialertview ×1
uiimageview ×1
uipickerview ×1
while-loop ×1