我试图UICollectionView动态设置节标题的高度,但使用下面的代码,我没有看到任何变化.视图是使用正确的项目绘制的,但高度不会让步.很抱歉,如果这是一个重复的问题,但我似乎找不到任何与该UICollectionView对象有关的内容.提前致谢.
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
{
PhotoVideoHeaderCell *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:@"videoHeaderView"
forIndexPath:indexPath];
if (indexPath.section == 0) {
// photos
[headerView setSection:@"Photo"];
} else {
[headerView.VehicleDetailView removeFromSuperview];
CGRect frame = headerView.frame;
frame.size.height = 60;
[headerView setFrame:frame];
[headerView setNeedsDisplay];
[headerView setBackgroundColor:[UIColor grayColor]];
[headerView setSection:@"Video"];
}
return headerView;
}
Run Code Online (Sandbox Code Playgroud) 我需要连接两个NSStrings,我编写了下面的代码:
NSString *reverseResult = [[NSString alloc] initWithFormat:@""];
NSString *zero = [[NSString alloc] initWithFormat:@"0"];
NSString *one = [[NSString alloc] initWithFormat:@"1"];
int modRes;
while (num != 0) {
modRes = num;
modRes = num % 2;
if (modRes == 0)
[reverseResult stringByAppendingString:zero];
else
[reverseResult stringByAppendingString:one];
num = num / 2;
}
Run Code Online (Sandbox Code Playgroud)
当我调试代码时,我看到"stringByAppendingString"没有做我需要的东西(reverseResult保持@"",即使它到达那一行).
代码有问题吗?
我正在实现一个自定义的UICollectionViewCell,我想知道如何向它发送模型数据,以便数据可用于初始化单元的子视图.
我通过做注册我的MyCollectionViewCell
[self.collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"MyCell"];
Run Code Online (Sandbox Code Playgroud)
在以下方法中,我做...
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCollectionViewCell* cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,当一个单元不在重用队列中时,它通过调用initWithFrame方法(文档确认应该发生)来初始化一个新单元.但是,我的MyCollectionViewCell类中有一个自定义的init方法,它是......
-(id) initWithFrame:(CGRect)frame withData: (NSDictionary*) data;
Run Code Online (Sandbox Code Playgroud)
我希望调用自定义初始化方法.我该怎么办?我没有使用任何笔尖,我正在以编程方式执行所有操作.
如果没有办法,我必须使用initWithFrame方法,我还能如何将模型数据传递给MyCollectionViewCell,以便我可以用该数据初始化子视图?
谢谢!
我正在尝试UIWebView在我的iPad应用程序中包含基于浏览器的浏览器.这需要一些时间,这使得调试变得困难,但应用程序最终崩溃,总是在同一点上:在JavaScriptCore WTF::StringImpl::hash()函数上的WebThread .它产生EXC_BAD_ACCESS (SIGSEGV), KERN_INVALID_ADDRESS at 0x00000001.
的UIWebView是通过在叠层状的方式的另一视图控制器(容器)管理的视图控制器内部.我只在内存中保留了四个或更少的浏览器.
有关崩溃日志的任何信息,或关于可能导致崩溃的原因?
这是Web线程的崩溃日志:
Thread 2 name: WebThread
Thread 2 Crashed:
0 JavaScriptCore 0x32a97d46 WTF::StringImpl::hash() const + 42
1 JavaScriptCore 0x32a97c6a WTF::HashTable<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityExtractor<WTF::StringImpl*>, WTF::StringHash, WTF::HashTraits<WTF::StringImpl*>, WTF::HashTraits<WTF::StringImpl*> >::lookupForWriting(WTF::StringImpl* const&) + 18
2 JavaScriptCore 0x32a9b028 std::pair<WTF::HashTableIterator<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityExtractor<WTF::StringImpl*>, WTF::StringHash, WTF::HashTraits<WTF::StringImpl*>, WTF::HashTraits<WTF::StringImpl*> >, bool> WTF::HashTable<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityExtractor<WTF::StringImpl*>, WTF::StringHash, WTF::HashTraits<WTF::StringImpl*>, WTF::HashTraits<WTF::StringImpl*> >::add<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityHashTranslator<WTF::StringImpl*, WTF::StringImpl*, WTF::StringHash> >(WTF::StringImpl* const&, WTF::StringImpl* const&) + 448
3 JavaScriptCore 0x32a9ae30 WTF::AtomicString::addSlowCase(WTF::StringImpl*) + 96
4 WebCore …Run Code Online (Sandbox Code Playgroud) -[SDImageCache initWithNamespace]执行dispatch_sync分配NSFileManager.dispatch_async在这里做单线的理由或好处是什么?请参阅第78行的完整代码.
// Init the disk cache
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
_diskCachePath = [paths[0] stringByAppendingPathComponent:fullNamespace];
dispatch_sync(_ioQueue, ^
{
_fileManager = NSFileManager.new;
});
Run Code Online (Sandbox Code Playgroud) 我试图显示和隐藏元素子元素,所以当我将鼠标悬停在<li>元素上时,我为所有元素设置了一个ng-show值false.如果我尝试使值true显示,它会显示所有子元素.我只想显示每个元素徘徊其孩子:
HTML代码:
<ul ng-init="show=false">
<li>
<a class="list-group-menu" href="#"><div class="icon-user"></div></a>
<div ng-show="show"> Profile </div>
</li>
<li>
<a class="list-group-menu" href="#"><div class="icon-scope"></div></a>
<div ng-show="show"> Scope </div>
</li>
<li>
<a class="list-group-menu" href="#"><div class="icon-job"></div></a>
<div ng-show="show"> Job </div>
</li>
<li>
<a class="list-group-menu" href="#"><div class="icon-login"></div>
<div ng-show="show"> Login </div>
</a>
</li>
<li>
<a class="list-group-menu" href="#"><div class="icon-register"></div></a>
<div ng-show="show"> Register </div>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
JQUERY CODE:
$('ul li').mouseenter(function() {
$(this).children('div').show();
});
$('ul li').mouseleave(function() {
$(this).children('div').hide();
});
Run Code Online (Sandbox Code Playgroud) 我该如何修复这个内存泄漏?我有 NSBezierPath 的集合吗?我该如何修复这个内存泄漏?有什么建议吗?我正在使用ARC。
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
for(int j=0;j<5000;j++){
NSLog(@"Hello, World!");
NSSize imageSize = NSMakeSize(512, 512);
NSImage *image = [[NSImage alloc] initWithSize:imageSize];
//draw a line:
for(int i=0;i<1000;i++){
[image lockFocus];
float r1 = (float)(arc4random() % 500);
float r2 = (float)(arc4random() % 500);
float r3 = (float)(arc4random() % 500);
float r4 = (float)(arc4random() % 500);
[NSBezierPath strokeLineFromPoint:NSMakePoint(r1, r2) toPoint:NSMakePoint(r3, r4)];
}
//...
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, imageSize.width, imageSize.height)];
NSData …Run Code Online (Sandbox Code Playgroud) objective-c ×4
ios ×2
angularjs ×1
crash ×1
ios6 ×1
iphone ×1
javascript ×1
jquery ×1
macos ×1
memory-leaks ×1
nsstring ×1
sdwebimage ×1
uiwebview ×1
webkit ×1
xcode4.5 ×1