小编Vin*_*ngh的帖子

从viewcontroller获取appdelegate值

在Appdelegate.h中
我导入了playerviewcontroller两个Appdelegate.hAppdelegate.m文件.

  @class PlayerViewController; 
  @property(nonatomic)float volumeDelegate;        
Run Code Online (Sandbox Code Playgroud)

在Appdelegate.m

  @synthesize volumeDelegate;
 - (void)volumeChanged:(NSNotification *)notification
 {
volumeDelegate =1.0
    PlayerViewController *volumeObject=[[PlayerViewController alloc]init];
[volumeObject setVolumeForAVAudioPlayer];
}
Run Code Online (Sandbox Code Playgroud)

在Playerviewcontroller.h中

 -(void)setVolumeForAVAudioPlayer;
Run Code Online (Sandbox Code Playgroud)

在Playerviewcontroller.m中

@interface PlayerViewController ()
{
AppDelegate *appdelegate;

 }
  -(void)viewDidLoad
  {
  appdelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  }

  -(void)setVolumeForAVAudioPlayer
  {
[appdelegate.sharedplayer  setVolume:appdelegate.volumeDelegate];
NSLog(@"System Volume in player view:  %f",appdelegate.volumeDelegate);
 }
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我得到volumeDelegate零值如下.

播放器视图中的系统音量:0.000000000

我在这里犯的错误是什么?

objective-c viewcontroller ios appdelegate

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

在打开的相机上呈现相机胶卷UIImagePickerController

在我的应用程序上,我有一个cameraOverlayView打开相机,带有自定义控件,用于相机按钮.该应用程序允许用户在关闭相机之前拍摄多张照片,因此快门按钮不会调用dismissViewControllerAnimated,而是在您完成拍照时有一个关闭按钮.

现在,相机覆盖图上的一个按钮是一个图库按钮,允许用户选择保存的图像而不是拍摄新的图像.我尝试了两种不同的方法来完成这项工作,但都失败了.

第一种方法

使用UIImagePickerController当前显示叠加层的相同实例并切换sourceType到库.它确实呈现了画廊,但是当拍摄照片时,我不能在不解雇整个叠加层的情况下解雇厨房.

第二种方法

创建一个单独的实例UIImagePickerController,设置sourceType为库并尝试调用presentViewController,然后失败并显示警告:

"警告:尝试在窗口层次结构中显示其视图!"

有没有人有这个问题的解决方案?这甚至可能吗?

objective-c uiimagepickercontroller ios

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

如何在使用UITableView registerNib时分配File的所有者:从nib加载自定义UITableViewCell?

所以我一直在考虑使用UITableView's registerNib:[dequeueReusableCellWithIdentifier: forIndexPath:]加载一个自定义UITableCellView的一个NIB.以下是我的控制器的重要部分:

- (void)viewDidLoad

[super viewDidLoad];
self.tableView.bounces = NO;
[self.tableView registerNib:[UINib nibWithNibName:@"ProgramListViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

TVProgramListTableViewCell *cell = (TVProgramListTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

cell.frame = CGRectMake(0, 0, CELLWIDTH, OPENCELLHEIGHT);
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.clipsToBounds = YES;

cell.titleLabel.text = [NSString stringWithFormat:@"herpa derp: %i", indexPath.row];

return cell;
Run Code Online (Sandbox Code Playgroud)

所以我正在注册NIB视图加载时,然后将其用于单元格出列.到目前为止,一切都像我期望的那样工作.我的自定义TVProgramListTableViewCell正在从中正确加载NIB并且IBOutlet正在连接.

NIB包含一个带有按钮的视图,我想向控制器发出激活事件.我可以将文件的所有者类型设置为我的表视图控制器类,但我不知道如何实际连接文件的所有者.

现在,如果我正在使用loadNibNamed:,并加载NIB自己,连接文件的所有者将很容易.有没有办法在利用时实现这一目标registerNib?除了无法连接文件所有者之外,这似乎是使用自定义单元格的完美方式UITableView.

objective-c uitableview ios

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

在UIPageViewController中释放未使用的页面

我正在为基于图画书的每个基页使用单独的.h,.m.xib文件.每个页面都加载了动画,音乐等,并占用大约4MB的内存.在Instruments中,每个页面加载时,可用内存下降约4MB.翻页时,永远不会释放此内存.它最终会给出内存警告. 似乎保持每个页面在内存中实例化,并且不会卸载它.因此,当页面快速转动时,应用程序崩溃.UIViewControllerUIPageViewControllerUIPageViewController

我希望能够卸载除了UIPageViewController前一页,当前页和下一页所需的3页以外的所有页面.如何卸载不需要的页面,因为它们被实例化了UIPageViewController.

下面是UIPageViewController从中拉出的页面数组.所有页面(Page1,Page2等)基本上只是加载图像文件,提供基本动画和音乐.

    //ARRAY OF PAGES    
pageArray = [[NSArray alloc] initWithObjects:
        (id)[[Page1 alloc] initWithNibName:nil bundle:nil],
            [[Page2 alloc] initWithNibName:nil bundle:nil],    
            [[Page3 alloc] initWithNibName:nil bundle:nil],    
            [[Page4 alloc] initWithNibName:nil bundle:nil],    
            [[Page5 alloc] initWithNibName:nil bundle:nil],    
            [[Page6 alloc] initWithNibName:nil bundle:nil], 
            [[Page7 alloc] initWithNibName:nil bundle:nil],
            [[Page8 alloc] initWithNibName:nil bundle:nil],
             // continues all the way up to page 47
             [[Page47 alloc] initWithNibName:nil bundle:nil],
             nil];
Run Code Online (Sandbox Code Playgroud)

我遗漏了标准的初始化UIPageViewController.它使用" nextPageNumber"从pageArray上面拉出右页以创建新的页面对象. …

xcode memory-management ios automatic-ref-counting uipageviewcontroller

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

如何计算帧大小以逐行绘制CoreText

我试图动态创建基于长期NSAttributedString分割成多个部分的书页.

我现在正在做的是使用此类别NSAttributedString:

@interface NSAttributedString (Height)
- (CGFloat)boundingHeightForWidth:(CGFloat)inWidth;
@end

@implementation NSAttributedString (Height)

- (CGFloat)boundingHeightForWidth:(CGFloat)inWidth
{
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFMutableAttributedStringRef)self); 
    CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, CGSizeMake(inWidth, 10000), NULL);
    CFRelease(framesetter);
    return suggestedSize.height ;
}
@end
Run Code Online (Sandbox Code Playgroud)

由于我使用a绘制文本CTFramesetter,因此工作正常并且正确返回了正确的框高度.不幸的是现在我需要逐行绘制文本:

-(void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();

// Flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
//CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

NSArray *lines = (__bridge NSArray *)(CTFrameGetLines(ctFrame));

CFIndex lineCount = [lines count];

for(CFIndex idx = 0; idx < lineCount; idx++)
{ …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ipad core-text ios

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

如何使用UITabbarsystemitem设置标题

我只想知道如何设置标签栏项目的标题UITabBarSystemItem

我做了什么 :

self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];

所以要默认更改标题而不是"精选"(因为UITabBarSystemItemFeatured对象),我写道:

self.tabBarItem.title = @"Actu";

所以在我看来,我应该把"Actu"作为标题而不是"精选".

但它没有任何改变,标题保持"特色"(默认标题).

我也尝试过:

[[self.tabBarController.tabBar.items objectAtIndex:0] setTitle:NSLocalizedString(@"Actu", @"Actu")];

(因为这个tabbaritem在索引0处),但没有任何变化.

或者使用UITabBarSystemItem对象可能无法进行这样的修改?

我希望这个解释得很好:/

PS:对不起我的英语和其他任何错误,第一篇文章...:/

objective-c uitabbaritem ios

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

将图像异步加载到UICollectionView?

如何将图像UICollectionview异步加载?内幕方法如下?

- (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

 bookImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", docPath, [[preview objectAtIndex:indexPath.row] lastPathComponent]]];
 [[cell grid_image] setImage:bookImage];

}
Run Code Online (Sandbox Code Playgroud)

viewdidload()中我使用以下异步调用将图像加载到"预览"NSMutablearray

 dispatch_queue_t imageLoadQueue = dispatch_queue_create("com.GMM.assamkar", NULL);

dispatch_async(imageLoadQueue, ^{
    //Wait for 5 seconds...
    usleep(1000000);
    docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];


    for(int k=0; k <[allImage count] ;k++){


        imgURL = [allImage objectAtIndex:k];
        [imagePreview addObject:imgURL];
        imgData=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]];


        [imgData writeToFile:[NSString stringWithFormat:@"%@/%@", docPath, [allImage lastPathComponent]] atomically:YES];

    }

    [[self collectionView] reloadData];


});
Run Code Online (Sandbox Code Playgroud)

请帮帮我..现在花了太多时间装货......

asynchronous objective-c ios uicollectionview

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

多次调用viewDidLoad/loadView

在我以编程方式启动的其中一个视图中,我看到了对' loadView/ viewdidLoad'的5个不同调用,但我不明白为什么这么多被调用.有人可以向我解释这背后的机制吗?

我以下列方式在父级UIViewController(TabBar+ NavigationBar应用程序的一部分)实例中启动视图:

MainEditController *editController = [[MainEditController alloc] initWithNibName:@"MainEditView" bundle:nil];           
[self.navigationController pushViewController:editController animated:YES];         
[editController release];   
Run Code Online (Sandbox Code Playgroud)

然后我记录MainEditController's viewDidLoadloadView方法(并调用他们各自的超级方法).

' MainEditView'nib包含3个项目:-File的所有者(类型MainEditController), - 第一个响应者(类型UIResponder)-View(类型UIView)

视图插座连接到文件所有者,视图中没有元素.我打算做的是在主视图中添加几个子视图,并根据特定条件显示其中一个子视图.

我认为两者viewDidLoadloadView会得到被称为控制器内的许多意见(1在这种情况下),但似乎并没有成为一个有效的假设.

iphone

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

CLLocationManager - 计算iPhone上的实时速度

如何计算设备上的实时速度?我已经google了很多,但我得到的只是在完成旅程后计算距离和速度.我可以在运行时计算速度吗?

建议将不胜感激.

提前致谢.

real-time cllocationmanager ios

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

UICollectionViewCell中的UITableView,点击单元格时会突出显示所有UITableViewCell

我正在制作UICollectionView一些UICollectionViewCells包含一个的地方UITableView.

这很好用,一切都很好,直到我点击UICollectionViewCell其他地方而不是UITableView.这会导致在表中的setHighlighted所有方法上调用该方法UITableViewCells.

下面是一个粗略的观点UICollectionViewCell.在UITableView从"单元一"到"单元三"只有跨越.点击此表外的任何位置,但内部UICollectionViewCell会导致单元格突出显示.

-------------------------
| Title goes here       |
|                       |
-------------------------
|                       |
|   Cell one            |
-------------------------
|                       |
|   Cell two            |
-------------------------
|                       |
|   Cell three          |
-------------------------
| Button outside table  |
|-----------------------|
Run Code Online (Sandbox Code Playgroud)

调用堆栈看起来像这样.

[MyTableViewCell setHighlighted:]
[UICellHighlightingSupport highlightView:]
UIApplicationMain
main
Run Code Online (Sandbox Code Playgroud)

似乎UICollectionViewCell前锋是所有细胞的一个亮点命令.

我通过setHighlightedUITableViewCell子类中重载方法而不是调用超级实现来解决这个问题.虽然看起来有点hacky,我想知道这种行为是否可以以某种方式避免.

编辑: 我认为这种行为来自UICollectionCellView于所有孩子的呼叫setHighlighted.我理解的在大多数其他情况下都很有用.

objective-c uitableview ios

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