小编Mat*_*uch的帖子

iOS setContentOffset无法在ipad上运行

这真的很奇怪.我有一个包含三个图像的滚动视图,用户滑动以查看下一个图像.但是,我希望第一个屏幕从中间图像开始.简单; 我将使用setContentOffset,一切都会好的.

该代码适用于iPhone模拟器,但不适用于iPad模拟器(或设备!)

CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat height = CGRectGetHeight(screen);
CGFloat width = CGRectGetWidth(screen);

CGPoint rightOffset = CGPointMake(width, 0);
[scrollView setContentOffset:rightOffset animated:YES];
Run Code Online (Sandbox Code Playgroud)

所有设置都在添加scrollView之前设置(实际上我们可以在添加了相同结果的scrollview之后执行此操作).

宽度在ipad上返回768,在iphone上返回320.

这是一个错误吗?Xcode 4.4.1和ios 6.

编辑:

看起来这与创建顺序有关; 移动到viewWillAppear而不是viewDidLoad,显然是在iphone和ipad上工作.只是不一致是非常令人惊讶的....

scrollview uiscrollview ios

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

呈现具有自定义大小的UIViewController

我一直在墙上敲打着我的头.我有一个使用Master-Detail SplitViewController作为其演示框架的iPad应用程序.我需要在应用程序首次加载时显示登录对话框,并使其具有自定义大小.我在主故事板中创建了一个UIViewController场景,并在DetailController首次加载时加载VC.

我遇到的问题是我无法控制VC的大小.我将它定义为FormSheet,以纵向模式显示.我将Presentation设置为FormSheet.我尝试以几种不同的方式明确设置大小,但绝对没有任何作用.

根本问题在于,由于所有这一切,VC 总是以全屏形式呈现为肖像.当我旋转到横向时,它将保持纵向模式,在左右两侧留下间隙,并切断视图的顶部和底部.

这令人难以置信的沮丧,我真的不知道从哪里开始.有趣的是,在app完全加载后,我使用tap来呈现完全相同类型的VC.它呈现出精美,使用以下设置:

MyViewController *itemDetails;

itemDetails = [Globals.storyboard   instantiateViewControllerWithIdentifier:@"MyViewController"];

itemDetails.itemImage.image = imageView.image;
itemDetails.jewelryObject = jewelryObject;

itemDetails.delegate = self;

itemDetails.modalPresentationStyle = UIModalPresentationPageSheet;
itemDetails.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:itemDetails];

itemDetails.navigationItem.title = jewelryObject.itemDescription;

[navigationController setModalPresentationStyle:UIModalPresentationFormSheet];

[self presentViewController:navigationController animated:YES completion:nil];

navigationController.view.superview.autoresizingMask =
    UIViewAutoresizingFlexibleTopMargin |
    UIViewAutoresizingFlexibleBottomMargin;

navigationController.view.superview.frame = CGRectMake(
    itemDetails.view.superview.frame.origin.x,
    itemDetails.view.superview.frame.origin.y,
    540.0f,
    450.0f
    );
navigationController.view.superview.center = self.view.center;

self.itemDetails = itemDetails;
Run Code Online (Sandbox Code Playgroud)

我非常沮丧,甚至无法表达.尽管我喜欢iOS编程,但偶尔有一些WTF时刻让我希望自己是一个隐士.如果有人有任何"啊哈!" 他们可以向我倾诉的见解,我真的很感激.

popupwindow uiviewcontroller window-resize ios

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

双引号在Xcode的搜索路径中表示什么?

今晚我们遇到了一个恼人的问题,只能在Xcode的命令行构建中出现,而不是来自Xcode的GUI.

当从具有Xcode GUI的机器构建时,使用$ PROJROOT的递归用户头搜索路径,没有双引号,我们没有遇到任何问题.但是,当使用使用Xcode命令行构建功能的Jenkins进行构建时,会抛出Headers不可用的错误.

经过一个小时的探索,有人决定尝试用双引号包装反复的$ PROJROOT("$ PROJROOT").一旦发生这种情况,Jenkins命令行的建设终于成功了.

所以我们并不完全理解用引号包装搜索路径或省略引号的后果.

任何人都可以了解究竟是什么导致了这个问题?什么双引号从命令行对GUI表示编译器?

xcode search-path ios jenkins

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

从OS X中的剪贴板获取文件路径

我希望我的应用程序能够将文件的完整路径复制到剪贴板之前.

我试过这个:

NSPasteboard *p = [NSPasteboard generalPasteboard];
NSDictionary *options = [NSDictionary dictionary];
NSString *path = [[p readObjectsForClasses:[NSArray arrayWithObjects:[NSString class], nil] options:options] objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)

这只返回文件名,而不是路径.

你能帮助我吗?

macos clipboard cocoa nspasteboard

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

如何从带有sectionNameKeyPath的NSFetchedResultsController获取numberOfRowsInSection

我有一个属性为"group"的实体,因为我想通过"group"(0或1)将我的实体列表分成2个部分

@property (nonatomic, retain) NSNumber * group;
Run Code Online (Sandbox Code Playgroud)

在我的fetchedResultsController中,我将sectionNameKeyPath指定为"group"

self.fetchedResultsController = [[NSFetchedResultsController alloc] 
    initWithFetchRequest:request managedObjectContext:self.managedObjectContext 
    sectionNameKeyPath:@"group" cacheName:nil];
Run Code Online (Sandbox Code Playgroud)

如何在下面的方法中返回每个部分中的行数?我收到以下错误:

Terminating app due to uncaught exception 'NSRangeException', reason: 
'-[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
Run Code Online (Sandbox Code Playgroud)

这是代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[[self.fetchedResultsController sections] objectAtIndex:section] 
        numberOfObjects];
}
Run Code Online (Sandbox Code Playgroud)

我也尝试了这个,得到了同样的错误:

id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]
    objectAtIndex:section];
return [sectionInfo numberOfObjects];
Run Code Online (Sandbox Code Playgroud)

请注意,我也实现了此方法:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
Run Code Online (Sandbox Code Playgroud)

core-data uitableview nsfetchedresultscontroller ios

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

在特定索引处将NSMutableDictionary添加到NSMutableArray?

我试图在特定索引上将NSMutableDictionary添加到NSMutableArray中

NSMutableArray已填充数据来自webservice,但我想要

在0索引上添加我的数组中的另一个字典.

但我有点困在这里:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ' -[JKArray insertObject:atIndex:]: mutating method sent to immutable object'
Run Code Online (Sandbox Code Playgroud)

我的代码是:

在.h文件中

@property (strong, nonatomic)NSMutableArray *cityArray;

@property (strong, nonatomic)NSMutableDictionary *cityDict;

.m file:

- (void)viewDidLoad
{
    [super viewDidLoad];


    self.cityArray = [[NSMutableArray alloc]init];

self.cityDict  = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"All Cities",@"key1", nil];

    NSLog(@"City Dict=> %@", cityDict);
}


-(void)ConnectionDidFinishLoading:(NSString *)responseString :(NSString *)serviceName{

        self.dealsDict = [responseString objectFromJSONString];

        self.cityArray = [self.dealsDict objectForKey:@"Cities"];

        [self.cityArray addObject:[self.cityDict copy]];

        [self.cityArray addObject:self.cityDict];

        [self.cityArray objectAtIndex:0];

        [self.tableView reloadData];

}
Run Code Online (Sandbox Code Playgroud)

请帮忙

谢谢.

objective-c nsmutablearray nsmutabledictionary

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

NSNumber 导致应用程序崩溃

我在 .h 文件中有一个 @property opacity

@property (assign) NSNumber *opacity;
Run Code Online (Sandbox Code Playgroud)

然后在 .m 文件中我

@synthesize opacity;
Run Code Online (Sandbox Code Playgroud)

然后在

- (id)initWithFrame:(NSRect)frame
Run Code Online (Sandbox Code Playgroud)

我做了

 opacity = [NSNumber numberWithFloat:1.0];
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序时,Xcode 显示此错误

Thread 1: EXC_BAD_ACCESS (code-EXC_I386_GPFLT)
Run Code Online (Sandbox Code Playgroud)

但是,如果我将该行更改为

opacity = [NSNumber numberWithInteger:1];
Run Code Online (Sandbox Code Playgroud)

一切正常。

objective-c nsnumber

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

只有在没有关系的情况下才能正确处理对象的删除?

我有一个Person属于Department一对多关系的实体.

我希望能够删除Department时,有没有更多的Person与它(或者通过缺失的相连的S Person实体,或更改了Persondepartment属性).现在,我正在尝试使用以下处理程序NSManagedObjectContextObjectsDidChangeNotification(目前只是尝试查看删除,并正确删除):

- (void)managedObjectDidChange:(NSNotification *)notification {

    NSSet *updatedObjects = [[notification userInfo] objectForKey:NSDeletedObjectsKey];
    for (NSManagedObject *obj in updatedObjects) {
        if ([obj.entity.name isEqualToString:@"Person"]) {
            NSLog(@"Person Changed");

            NSManagedObject *department = [(Person *)obj department];
            NSLog(@"%i", [[department valueForKey:@"person"] count]);

            if ([[department] valueForKey:@"person"] count] == 0) {
                NSLog(@"Department has no more people associated with it");
                // deletion code
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我删除某个人时,与该部门相关联的人数不会改变.我没有对Department实体进行提取.那是我应该做的吗?

cocoa cocoa-touch core-data nsmanagedobject nsmanagedobjectcontext

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

更新iOS 5中的进度条

我正在开发一个iOS音频播放器,我想实现一个进度条,它将指示正在播放的当前歌曲的进度.在我的ViewController类中,我有2个双实例 - 时间和持续时间,以及一个名为background的AVAudioPlayer实例.

- (IBAction)play:(id)sender {
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"some_song" ofType:@"mp3"];
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    background = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
    background.delegate = self;
    [background setNumberOfLoops:1];
    [background setVolume:0.5];
    [background play];
    time = 0;
    duration = [background duration];
    while(time < duration){
        [progressBar setProgress: (double) time/duration animated:YES];
        time += 1; 
    } 
}
Run Code Online (Sandbox Code Playgroud)

谁能解释我做错了什么?提前致谢.

iphone avaudioplayer ios progress-bar

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

如何将导航栏标题设置为可编辑的文本字段?

我希望用户能够编辑导航栏的标题.我觉得我之前在应用程序中看过它.这可能吗?

iphone cocoa-touch uinavigationbar

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