在Appdelegate.h中
我导入了playerviewcontroller两个Appdelegate.h和Appdelegate.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
我在这里犯的错误是什么?
在我的应用程序上,我有一个cameraOverlayView打开相机,带有自定义控件,用于相机按钮.该应用程序允许用户在关闭相机之前拍摄多张照片,因此快门按钮不会调用dismissViewControllerAnimated,而是在您完成拍照时有一个关闭按钮.
现在,相机覆盖图上的一个按钮是一个图库按钮,允许用户选择保存的图像而不是拍摄新的图像.我尝试了两种不同的方法来完成这项工作,但都失败了.
第一种方法
使用UIImagePickerController当前显示叠加层的相同实例并切换sourceType到库.它确实呈现了画廊,但是当拍摄照片时,我不能在不解雇整个叠加层的情况下解雇厨房.
第二种方法
创建一个单独的实例UIImagePickerController,设置sourceType为库并尝试调用presentViewController,然后失败并显示警告:
"警告:尝试在窗口层次结构中显示其视图!"
有没有人有这个问题的解决方案?这甚至可能吗?
所以我一直在考虑使用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.
我正在为基于图画书的每个基页使用单独的.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
我试图动态创建基于长期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) 我只想知道如何设置标签栏项目的标题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:对不起我的英语和其他任何错误,第一篇文章...:/
如何将图像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)
请帮帮我..现在花了太多时间装货......
在我以编程方式启动的其中一个视图中,我看到了对' 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 viewDidLoad和loadView方法(并调用他们各自的超级方法).
' MainEditView'nib包含3个项目:-File的所有者(类型MainEditController), - 第一个响应者(类型UIResponder)-View(类型UIView)
视图插座连接到文件所有者,视图中没有元素.我打算做的是在主视图中添加几个子视图,并根据特定条件显示其中一个子视图.
我认为两者viewDidLoad并loadView会得到被称为控制器内的许多意见(1在这种情况下),但似乎并没有成为一个有效的假设.
如何计算设备上的实时速度?我已经google了很多,但我得到的只是在完成旅程后计算距离和速度.我可以在运行时计算速度吗?
建议将不胜感激.
提前致谢.
我正在制作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前锋是所有细胞的一个亮点命令.
我通过setHighlighted在UITableViewCell子类中重载方法而不是调用超级实现来解决这个问题.虽然看起来有点hacky,我想知道这种行为是否可以以某种方式避免.
编辑:
我认为这种行为来自UICollectionCellView于所有孩子的呼叫setHighlighted.我理解的在大多数其他情况下都很有用.
ios ×9
objective-c ×7
iphone ×2
uitableview ×2
appdelegate ×1
asynchronous ×1
core-text ×1
ipad ×1
real-time ×1
uitabbaritem ×1
xcode ×1