当前位置:  编程技术>移动开发
本页文章导读:
    ▪UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的有关问题)        UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题) 假如你是用代码方式直接将控件(如UILabel、UIButton等)加到UITableView的cell中去的话,,,在出了 - (UI.........
    ▪ [转]掩藏虚拟按键(导航栏)的方法        [转]隐藏虚拟按键(导航栏)的方法 Controls for system UI visibilitySince the early days of Android, the system has managed a UI component known as the status bar, which resides at the top of handset devices to deliver information such a.........
    ▪ 点击Run旋钮后Stop按钮变灰       点击Run按钮后Stop按钮变灰 当把应用程序从模拟器删除(长按AppIcon,图标晃动,出现叉号,点击叉号。点击主屏幕按钮就不晃动了)之后,再次运行应用程序后,Stop按钮就变灰色,应用程序.........

[1]UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的有关问题)
    来源: 互联网  发布时间: 2014-02-18
UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)


假如你是用代码方式直接将控件(如UILabel、UIButton等)加到UITableView的cell中去的话,,,在出了

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   //自定义代码
  return cell; 
 }

这个函数后,,,当你点击cell的时候想知道到底是点击了第几行,,这时候你就可以通过在以下代码获得点击的行数。

    UITableViewCell *cell = (UITableViewCell *)[btn superview];
    NSIndexPath *indexPath = [_myTableView indexPathForCell:cell];
    NSLog(@"indexPath is = %i",indexPath.row);

注释:btn是你通过代码的方式添加到cell的一个Button,_myTableView是UITableView的一个关联变量。


假如你是通过新建 .xib的方式新建一个继承UITableViewCell的 .xib(例如:shopCell.xib)文件添加到原有UITableView的cell的方式的话,,,用上面这种方法是获取不到点击cell所在的行数的,也就是说你不知道点击的cell到底是第几行。


同样可以用上面的代码,,不过要稍微修改一下:

    UITableViewCell *cell = (UITableViewCell *)[[[btn superview] superview] superview];
    NSIndexPath *indexPath = [_myTableView indexPathForCell:cell];
    NSLog(@"indexPath is = %i",indexPath.row);


解释:第一句代码中的[btn superview]是shopCell 的contentView,第二个superview是shopCell自己本身的cell,第三个superview是UITableView的cell,,注意不要弄混淆了。




    
[2] [转]掩藏虚拟按键(导航栏)的方法
    来源: 互联网  发布时间: 2014-02-18
[转]隐藏虚拟按键(导航栏)的方法
Controls for system UI visibility

Since the early days of Android, the system has managed a UI component known as the status bar, which resides at the top of handset devices to deliver information such as the carrier signal, time, notifications, and so on. Android 3.0 added the system bar for tablet devices, which resides at the bottom of the screen to provide system navigation controls (Home, Back, and so forth) and also an interface for elements traditionally provided by the status bar. In Android 4.0, the system provides a new type of system UI called the navigation bar. You might consider the navigation bar a re-tuned version of the system bar designed for handsets—it provides navigation controls for devices that don’t have hardware counterparts for navigating the system, but it leaves out the system bar's notification UI and setting controls. As such, a device that provides the navigation bar also has the status bar at the top.

To this day, you can hide the status bar on handsets using the FLAG_FULLSCREEN flag. In Android 4.0, the APIs that control the system bar’s visibility have been updated to better reflect the behavior of both the system bar and navigation bar:

    The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.
    The SYSTEM_UI_FLAG_VISIBLE flag replaces the STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.
    The SYSTEM_UI_FLAG_HIDE_NAVIGATION is a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets). The navigation bar returns to view as soon as the system receives user input. As such, this mode is useful primarily for video playback or other cases in which the whole screen is needed but user input is not required.

You can set each of these flags for the system bar and navigation bar by calling setSystemUiVisibility() on any view in your activity. The window manager combines (OR-together) all flags from all views in your window and apply them to the system UI as long as your window has input focus. When your window loses input focus (the user navigates away from your app, or a dialog appears), your flags cease to have effect. Similarly, if you remove those views from the view hierarchy their flags no longer apply.

To synchronize other events in your activity with visibility changes to the system UI (for example, hide the action bar or other UI controls when the system UI hides), you should register a View.OnSystemUiVisibilityChangeListener to be notified when the visibility of the system bar or navigation bar changes.

See the OverscanActivity class for a demonstration of different system UI options.

控制导航栏的显示有两种修改方法:
1.临时修改,通过方法mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)方法设置。注意该方法必须放在setContentView(mView)之前,具体代码如下:
public class HideTestActivity extends Activity implements OnClickListener{
	View main ;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        main = getLayoutInflater().from(this).inflate(R.layout.main, null);
        main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        main.setOnClickListener(this);
        setContentView(main);
    }

	@Override
	public void onClick(View v) {
		int i = main.getSystemUiVisibility();
		if (i == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {
			main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
		} else if (i == View.SYSTEM_UI_FLAG_VISIBLE){
			main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
		} else if (i == View.SYSTEM_UI_FLAG_LOW_PROFILE) {
			main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
		}
	}
}

2.永久隐藏法。修改系统文件/framework/base/core/res/res/values/config.xml的变量config_showNavigationBar值。如果不起作用,那就是该值被android.content.res.Configuration类的变量navigationHidden所取代,需要修改此值(搜索SystemUI得知,显示导航栏与否是通过方法mWindowManagerService.hasNavigationBar()判断的,该方法的实现是在PhoneWindowManager类里面mHasNavigationBar设置的。)

    
[3] 点击Run旋钮后Stop按钮变灰
    来源: 互联网  发布时间: 2014-02-18
点击Run按钮后Stop按钮变灰

当把应用程序从模拟器删除(长按AppIcon,图标晃动,出现叉号,点击叉号。点击主屏幕按钮就不晃动了)之后,再次运行应用程序后,Stop按钮就变灰色,应用程序停止运行,只有当点击模拟器上的图标才能继续。

这是因为点击了Clean,删除后直接运行就不会出现这个问题

一旦Clean,那么重启模拟器就好了

 

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3