单击切换按钮将显示菜单并向右滑出内容视图。动画完成后,内容视图的布局参数会更新到最终位置。
更新内容视图的最终位置时,该语句mViewContent.setLayoutParams(params);导致崩溃。错误信息是java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
Main.java > public class MainActivity extends Activity {}
public void onToggleButtonMenuClicked(View view) {
// Is the toggle on?
boolean toggleTurnedOn = ((ToggleButton) view).isChecked();
if (toggleTurnedOn) { // If the toggle is turned on
// Show menu
LinearLayout mViewMenu = (LinearLayout) findViewById(R.id.linear_layout_menu);
Animation animMenuOn = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_menu_on);
mViewMenu.startAnimation(animMenuOn);
LinearLayout mViewContent = (LinearLayout) findViewById(R.id.linear_layout_content);
Animation animContentOff = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_content_off);
mViewContent.startAnimation(animContentOff);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(480, 800);
params.leftMargin = 384; // Shift 384 pixels …Run Code Online (Sandbox Code Playgroud) 我有一个Android 2.2目标库项目,它MyLibraryGooglePlusSocialPlugin.java有一个import com.google.android.gms.plus.GooglePlusUtil;未能编译(GooglePlusUtil cannot be resolved),而其他人没关系:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.plus.PlusClient;
import com.google.android.gms.plus.PlusClient.OnPeopleLoadedListener;
import com.google.android.gms.plus.PlusClient.OnPersonLoadedListener;
import com.google.android.gms.plus.PlusShare;
import com.google.android.gms.plus.model.people.Person;
import com.google.android.gms.plus.model.people.PersonBuffer;
Run Code Online (Sandbox Code Playgroud)
我今天通过Android SDK管理器更新了相关的Google服务,并设置了构建路径和依赖关系.
考虑以下Vim ex命令,
:let i=1 | '<,'>g/^/ s/^\ *-/\=i/ | let i+=1
Run Code Online (Sandbox Code Playgroud)
它用选定行中的有序数替换标题短划线.
我不明白为什么这个命令作为从所选行的第一行到最后一行的循环.也就是说,怎么g能一遍let i+=1又一遍地重复.
根据Alexander Merchi在这篇文章(UINavigationBar中的UIBarButtonItem Custom视图)中给出的答案,找到了一个解决方案.但仍然不知道如何正确改变图像的位置.
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 28.0f, 28.0f)]; // 28 points is the width or height of the button image
[btn setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(onClickMenuButton) forControlEvents:UIControlEventTouchUpInside];
btnMenu = [[UIBarButtonItem alloc] initWithCustomView:btn];
Run Code Online (Sandbox Code Playgroud)

在iOS 6中,目标是这样的:

而目前的结果是这样的:

我的代码是
btnMenu = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"button.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(onClickMenuButton)];
Run Code Online (Sandbox Code Playgroud)
button.png是白色的圆圈,里面有白色的三个条纹和一个透明的背景.
当输入是一个字符时,以下简单程序将给出一个无限循环,尽管这意味着从数字中分辨出一个字符。如何scanf使用返回值测试是否假设某个字符是数字scanf?
#include <stdio.h>
int main() {
int n;
int return_value = 0;
while (!return_value) {
printf("Input a digit:");
return_value = scanf("%d", &n);
}
printf("Your input is %d\n", n);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 有时我们可以在synthesize语句中明确指定实例变量的名称,例如,
在SomeViewController.h,
//....
@property (nonatomic, retain) NSObject *variable;
//....
Run Code Online (Sandbox Code Playgroud)
在SomeViewController.m,
//....
@synthesize variable = _variable;
//....
Run Code Online (Sandbox Code Playgroud)
但是,如果将实例变量隐式命名为_variable即使我们简单地将它作为:
@synthesize variable;
Run Code Online (Sandbox Code Playgroud)
在SomeViewController.m.
任何人都可以分享为什么有必要吗?谢谢你:D
例如,我是子类UIView,其中myString定义了一个被调用的弱属性.@synthesize myString = _myString;语句有一条错误消息:Semantic Issue: @synthesize of 'weak' property is only allowed in ARC or GC mode.
该MyUIView.h文件中:
@interface MyUIView : UIView
@property (nonatomic, weak) NSString *myString;
@end
Run Code Online (Sandbox Code Playgroud)
该MyUIView.m文件中:
#import "MyUIView.h"
@implementation MyUIView
@synthesize myString = _myString; // This statement causes an error whose message is Semantic Issue: @synthesize of 'weak' property is only allowed in ARC or GC mode
- (void)dealloc
{
[_myString release];
[super dealloc];
} …Run Code Online (Sandbox Code Playgroud) 我正在学习内存管理一段时间.阅读Apple的内存管理指南以及其他作者的书籍/博客/论文/帖子.
令我困惑的是我是否应该写:
nameOfMySynthesizedProperty = [[NSObject alloc] init]; // version 1
Run Code Online (Sandbox Code Playgroud)
要么
nameOfMySynthesizedProperty = [[[NSObject alloc] init] autorelease]; // version 2
Run Code Online (Sandbox Code Playgroud)
在示例项目中,使用手动内存管理,没有dealloc方法,版本1用于所有类属性/ ivars.有时一些属性甚至没有合成但是它的吸气剂被使用,
这些都没有在我读过的教程/指南中讲授,但是这个示例项目顺利进行而没有崩溃......
任何人都可以给我一些亮点......
示例项目中使用手动内存管理.
另一个例子
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UIViewController *viewController;
@end
Run Code Online (Sandbox Code Playgroud)
AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// To be inserted with the following choices of code
}
@end
Run Code Online (Sandbox Code Playgroud)
在AppDelegate.m- > -(BOOL)application:application didFinishLaunchingWithOptions:方法中,以下哪个对于初始化是正确的self.window.rootViewController …
在bash脚本,一个的支架引述表达if语句没有分号的权利],根据部分shell脚本编程本的书.
但是分号可以在许多不同的教程或脚本中看到,例如本教程和此脚本片段:
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
Run Code Online (Sandbox Code Playgroud)
我什么时候必须在那里加分号?
window['someKeyword']在 JavaScript中是什么意思?
我猜 window 是DOM window object,但是检索属性的语法window.propertyName在我找到的引用中,而不是window['propertyName']. 这两种方法是找回财产吗?
objective-c ×3
android ×2
ios ×2
bash ×1
c ×1
compilation ×1
java ×1
javascript ×1
scanf ×1
vim ×1